Zum Hauptinhalt springen

Interface: OAuth2Client

Implement this interface for OAuth 2 APIs that use Authorization Code Grant.

The protocol flow is described in https://datatracker.ietf.org/doc/html/rfc6749#section-4.1

  • generateAuthRequest -> A-C in the RFC
  • exchangeGrant -> D-E in the RFC

Storing Access Tokens: To store the access tokens as secure as possible you need to create a field in your configuration with {isSecret: true}. This ensures that the access token is never transferred to the frontend but to your app. To set or update access tokens you can use SodaSync.context.config as usual.

Methods

exchangeGrant

exchangeGrant(request, state): void

This method is called after the user was redirected back from the external system. It should exchange authorization code with an access token.

Parameters

NameTypeDescription
requestObjectThe raw http request that contain the URL with all parameters such as code.
request.body?string-
request.headers?Record<string, string>-
request.method?string-
request.url?string-
stateRecord<string, string>The state data from the AuthRequest

Returns

void

Defined in

src/contracts/oauth/oauth2-client.ts:32


generateAuthRequest

generateAuthRequest(redirectUrl, state): Object

This method is called to initiate the OAuth 2 flow.

Parameters

NameTypeDescription
redirectUrlstringThe url for redirecting the user back.
statestringThe state string

Returns

Object

NameType
authUrl?string
state?Record<string, string>

Defined in

src/contracts/oauth/oauth2-client.ts:23