Authorizing a user
Send the user to Autentique, request permissions, and validate the authorization response.
Protect every authorization attempt
Value
Purpose
const base64url = (bytes) =>
btoa(String.fromCharCode(...bytes))
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
const randomValue = (length = 32) =>
base64url(crypto.getRandomValues(new Uint8Array(length)));
export async function createOAuthSession() {
const state = randomValue();
const codeVerifier = randomValue(64); // 86 characters, within the PKCE limit
const digest = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(codeVerifier),
);
return {
state,
codeVerifier,
codeChallenge: base64url(new Uint8Array(digest)),
};
}Build the authorization URL
Parameter
Value
Receive the callback
Handle denied authorization
Last updated