Package: react-wallet-kit
Defined in: react-wallet-kit/src/providers/client/Types.tsx:140
Overview
Handles the Discord OAuth 2.0 flow.- This function initiates the OAuth 2.0 PKCE flow with Discord by redirecting the user to the Discord authorization page or opening it in a popup window.
- It supports both “popup” and “redirect” flows, determined by the
openInPage
parameter. - Generates a new ephemeral API key pair and uses its public key as part of the state and a cryptographic nonce to bind the OAuth session.
- Creates a PKCE verifier/challenge pair, storing the verifier in
sessionStorage
for later use in the token exchange. - Constructs the Discord OAuth URL with all required parameters, including client ID, redirect URI, response type, scope, PKCE code challenge, nonce, and state.
- The
state
parameter encodes the provider name, flow type, ephemeral public key, and any additional key-value pairs provided inadditionalState
. - If
openInPage
is true, the current page is redirected to the OAuth URL and the function returns a promise that resolves on redirect or rejects after 5 minutes if no redirect occurs. - If
openInPage
is false, a popup window is opened for the OAuth flow, and the function returns a promise that resolves when the OAuth code is captured or rejects if the popup is closed or times out. - On receiving an authorization code, the function exchanges it for an OIDC token via the Turnkey proxy (
proxyOAuth2Authenticate
) using the PKCE verifier, redirect URI, and nonce. - On successful authentication, the function either calls the provided
onOauthSuccess
callback, triggers theonOauthRedirect
callback from provider callbacks, or completes the OAuth flow internally by callingcompleteOauth
. - Handles error cases such as missing configuration, popup failures, missing PKCE verifier, or Turnkey proxy failures, throwing a
TurnkeyError
with appropriate error codes.
Parameters
Response
A successful response returns the following fields:A promise that resolves when the OAuth flow is successfully initiated and completed, or rejects on error or timeout.