Website Integration

Leverage Turf's Auth in your platform

Integrating Turf Connect on the Website

  • Register your Platform

Register you platform by filling the Private Form and get the necessary OAuth credentials to access Turf Connect.

Soon after verifying the application, Turf will be sending out the credentials securely via email (provided in the form)

Never share your client_id &client_secret with anyone else

  • Implementing "Login with Turf" UI Component

Add a "Sign in with Turf" button that redirects users to Turf's authentication page.

URL to redirect to:

https://turf-connect.0xturf.gg?client_id=${client_id}&redirect_uri=${encodeURI(
      redirectUri)}&response_type=code&scope=identify

Please ensure that the redirectUri you provide is the same as the one you provided during registration.

The clientId should also be the one you received during registration.

Handle the redirect back to your site to receive the authorization code.

  • Exchanging Authorization Code for Access Token

After Turf redirects the user back to your application with the authorization code, you need to make a POST request to the oauth2/token endpoint to exchange the authorization code for an access token.

Endpoint:

let response = await fetch('https://test-api.0xturf.gg/v1/oauth2/token', {
          method: 'POST',
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            clientId: 'CLIENT_ID',
            clientSecret: 'CLIENT_SECRET',
            code: code,  // received authorization code goes here
          }),
        })
        
const res = await response.json()
console.log(res.data.accessToken)

  • Fetching User Details

Use the access token to request data from Turf's API, based on the granted permissions.

let response = await fetch('https://api.0xturf.gg/v1/partner/user/info', {
            method: 'POST',
            headers: {
              Accept: 'application/json',
              'Content-Type': 'application/json',
              Authorization: `Bearer ${res.data.accessToken}`,  // access token
            },
            body: JSON.stringify({
              clientId: 'CLIENT_ID',
              clientKey: 'CLIENT_SECRET',
            }),
          })

const user_data = await response.json()
console.log("User Data - ", user_data)

Last updated