TURF Docs
  • #️Overview
  • 🚨Problem in the Gaming Industry
  • *️Solution
  • Explore Turf
  • Turf Engine
  • Link to Whitepaper v2 - WIP
  • TURF ABSTRACTS
    • ☸️Overview - An Ecosystem
    • βš›οΈTURF Engine | ESports Facilitation Stack
      • What's in it for Games ?
        • Hosting ESports events for my Game
      • What's in it for ESports Hosts ?
        • How to be a part of the System ?
      • Tech Insights
        • Stack Elements
    • πŸ†”Turf ID
      • Overview | Self Soverign Identity for Gamers
      • Gamer's Portfolio
      • POA | Proof of Achievements
    • ☯️Dynamic Prediction Market
      • ESports x Prediction Market
      • Experience
      • Viewership Engagement
      • $TURF as a wager asset
    • πŸ•ŽTurf Connect
      • Discord Server Integration
      • Website Integration
    • β™‹Turf's Loyalty - xTurf
    • ♐Turf StackFund
  • HOW TO USE
    • ☸️ESports Hosts
      • 🀼Add your Community
      • πŸ—œοΈFirst Competition Setup
  • TURF Token
    • ♻️$TURF
    • 🎈Airdrop -> xTurf
      • How to Participate
      • Maximizing Your xTurf Earnings
    • Airdrop Page
    • FAQs
  • SUPPORT
    • πŸ“³Contact Us
    • Initiate a Support Ticket
Powered by GitBook
On this page
  1. TURF ABSTRACTS
  2. Turf Connect

Website Integration

Leverage Turf's Auth in your platform

PreviousDiscord Server IntegrationNextTurf's Loyalty - xTurf

Last updated 11 months ago

Integrating Turf Connect on the Website

  • Register your Platform

Register you platform by filling the 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)
πŸ•Ž
Private Form