Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 2.44 KB

createoauthhandler.md

File metadata and controls

34 lines (27 loc) · 2.44 KB

createOAuthHandler

Create a fetch request handler to handle an OAuth authentication flow. The credentials are stored in the installation configuration as installationCredentialsKey.

See the Configurations section to learn more.

ArgumentTypeDescription
clientId*stringID of the client application in the OAuth provider.
clientSecret*stringSecret of the client application in the OAuth provider.
authorizeURL*stringURL to redirect the user to, for authorization.
accessTokenURL*stringURL to exchange the OAuth code for an access token.
redirectURLstringRedirect URL to use. When the OAuth identity provider only accepts a static one.
scopesstring[]Scopes to ask for.
promptstringOptional configuration for a prompt during the OAuth process.
extractCredentialsfunctionExtract the credentials from the code exchange response.

*required

Example

const oauthHandler = createOAuthHandler({
            redirectURL: `${environment.integration.urls.publicEndpoint}/oauth`,
            clientId: environment.secrets.CLIENT_ID,
            clientSecret: environment.secrets.CLIENT_SECRET,
            authorizeURL: 'https://linear.app/oauth/authorize',
            accessTokenURL: 'https://api.linear.app/oauth/token',
            extractCredentials: (response) => {
                if (!response.ok) {
                    throw new Error(
                        `Failed to exchange code for access token ${JSON.stringify(response)}`
                    );
                }

                return {
                    configuration: {
                        oauth_credentials: { access_token: response.access_token },
                    },
                };
            },
});