Websites and web apps
The authorization code flow with PKCE: send the player to REAN, get a code back, exchange it for tokens.
1. Send the player to REAN
GET
https://reanstudios.com/oauth/authorize| Name | Type | Description |
|---|---|---|
client_idrequired | string | Your app's client id. |
redirect_urirequired | string | One of your registered redirect URIs. |
response_typerequired | string | Always code. |
scope | string | Space-separated, e.g. openid profile friends.read. Default openid. |
staterequired | string | Random value you store and check when the player comes back (CSRF protection). |
code_challenge | string | base64url(SHA-256(code_verifier)), 43 characters. Required for public clients. |
code_challenge_method | string | S256 |
nonce | string | Random value echoed in the ID token. |
prompt | string | consent to always show the consent screen; none to fail with consent_required instead of showing it. |
import { ReanAuth, localStorageStore } from '@rean/sdk'
const auth = new ReanAuth({
clientId: 'rean_xxxxxxxxxxxxxxxxxxxxxxxx',
redirectUri: 'https://yourgame.com/auth/callback',
scopes: ['openid', 'profile', 'friends.read'],
storage: localStorageStore(),
})
signInButton.onclick = () => auth.signInWithRedirect()2. Handle the redirect
The player comes back to your redirect URI with either a code or an error:
https://yourgame.com/auth/callback?code=rac_…&state=af0ifjsldkj&iss=https%3A%2F%2Fapi.reanstudios.com
https://yourgame.com/auth/callback?error=access_denied&error_description=The+player+declined.&state=af0ifjsldkjCheck state, then exchange the code within 5 minutes:
POST
https://api.reanstudios.com/api/oauth/token// on https://yourgame.com/auth/callback
const tokens = await auth.handleRedirect() // checks state and nonce
console.log(auth.user.preferred_username){
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6ImF0K2p3dCIs…",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "openid profile friends.read",
"id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIs…"
}Add offline_access to the scopes to also get a refresh_token. See Tokens and sessions.
3. Verify the ID token (servers)
If your server receives the ID token from the token endpoint itself, over TLS, the response is already trustworthy. If an ID token reaches your server any other way (e.g. sent up by your game client), verify it against REAN's keys:
import { createRemoteJWKSet, jwtVerify } from 'jose'
const JWKS = createRemoteJWKSet(new URL('https://api.reanstudios.com/api/oauth/jwks'))
const { payload } = await jwtVerify(idToken, JWKS, {
issuer: 'https://api.reanstudios.com',
audience: 'rean_xxxxxxxxxxxxxxxxxxxxxxxx',
})
// payload.sub is the REAN player id (stable, never reused)