From 7738a004b09063fd061b1071f6d00f3548e59dac Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 Apr 2022 14:20:59 +0200 Subject: [PATCH] auth-backend: migrate atlassian provider to use integration helper Signed-off-by: Patrik Oldsberg --- .../src/providers/atlassian/provider.ts | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/plugins/auth-backend/src/providers/atlassian/provider.ts b/plugins/auth-backend/src/providers/atlassian/provider.ts index e45b1dfedd..1cb83d4589 100644 --- a/plugins/auth-backend/src/providers/atlassian/provider.ts +++ b/plugins/auth-backend/src/providers/atlassian/provider.ts @@ -37,12 +37,12 @@ import { } from '../../lib/passport'; import { AuthHandler, - AuthProviderFactory, AuthResolverContext, RedirectInfo, SignInResolver, } from '../types'; import express from 'express'; +import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; export type AtlassianAuthProviderOptions = OAuthProviderOptions & { scopes: string; @@ -179,46 +179,59 @@ export type AtlassianProviderOptions = { }; }; -export const createAtlassianProvider = (options?: { - /** - * The profile transformation function used to verify and convert the auth response - * into the profile that will be presented to the user. - */ - authHandler?: AuthHandler; +/** + * Auth provider integration for atlassian auth + * + * @public + */ +export const atlassian = createAuthProviderIntegration({ + create(options?: { + /** + * The profile transformation function used to verify and convert the auth response + * into the profile that will be presented to the user. + */ + authHandler?: AuthHandler; - /** - * Configure sign-in for this provider, without it the provider can not be used to sign users in. - */ - signIn?: { - resolver: SignInResolver; - }; -}): AuthProviderFactory => { - return ({ providerId, globalConfig, config, resolverContext }) => - OAuthEnvironmentHandler.mapConfig(config, envConfig => { - const clientId = envConfig.getString('clientId'); - const clientSecret = envConfig.getString('clientSecret'); - const scopes = envConfig.getString('scopes'); - const customCallbackUrl = envConfig.getOptionalString('callbackUrl'); - const callbackUrl = - customCallbackUrl || - `${globalConfig.baseUrl}/${providerId}/handler/frame`; + /** + * Configure sign-in for this provider, without it the provider can not be used to sign users in. + */ + signIn?: { + resolver: SignInResolver; + }; + }) { + return ({ providerId, globalConfig, config, resolverContext }) => + OAuthEnvironmentHandler.mapConfig(config, envConfig => { + const clientId = envConfig.getString('clientId'); + const clientSecret = envConfig.getString('clientSecret'); + const scopes = envConfig.getString('scopes'); + const customCallbackUrl = envConfig.getOptionalString('callbackUrl'); + const callbackUrl = + customCallbackUrl || + `${globalConfig.baseUrl}/${providerId}/handler/frame`; - const authHandler: AuthHandler = - options?.authHandler ?? atlassianDefaultAuthHandler; + const authHandler: AuthHandler = + options?.authHandler ?? atlassianDefaultAuthHandler; - const provider = new AtlassianAuthProvider({ - clientId, - clientSecret, - scopes, - callbackUrl, - authHandler, - signInResolver: options?.signIn?.resolver, - resolverContext, + const provider = new AtlassianAuthProvider({ + clientId, + clientSecret, + scopes, + callbackUrl, + authHandler, + signInResolver: options?.signIn?.resolver, + resolverContext, + }); + + return OAuthAdapter.fromConfig(globalConfig, provider, { + providerId, + callbackUrl, + }); }); + }, +}); - return OAuthAdapter.fromConfig(globalConfig, provider, { - providerId, - callbackUrl, - }); - }); -}; +/** + * @public + * @deprecated Use `providers.atlassian.create` instead + */ +export const createAtlassianProvider = atlassian.create;