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.

*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 },
                    },
                };
            },
});

Last updated