From 6f5414273c9b6e87881766f8683684484016ffeb Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 26 Jul 2023 17:56:44 +0200 Subject: [PATCH] auth-node: add default OAuth profile transform Signed-off-by: Patrik Oldsberg --- .../src/oauth/PassportOAuthAuthenticatorHelper.ts | 9 +++++++++ plugins/auth-node/src/oauth/createOAuthHandlers.ts | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts b/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts index dc76207342..7c188435d5 100644 --- a/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts +++ b/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts @@ -21,6 +21,7 @@ import { OAuthAuthenticatorRefreshInput, OAuthAuthenticatorResult, OAuthAuthenticatorStartInput, + OAuthProfileTransform, } from './types'; /** @internal */ @@ -37,6 +38,14 @@ export type PassportOAuthResult = { /** @public */ export class PassportOAuthAuthenticatorHelper { + static defaultProfileTransform: OAuthProfileTransform = + async input => ({ + profile: PassportHelpers.transformProfile( + input.fullProfile, + input.session.idToken, + ), + }); + static from(strategy: Strategy) { return new PassportOAuthAuthenticatorHelper(strategy); } diff --git a/plugins/auth-node/src/oauth/createOAuthHandlers.ts b/plugins/auth-node/src/oauth/createOAuthHandlers.ts index 9f7bc7f6f9..e4fd3e5a50 100644 --- a/plugins/auth-node/src/oauth/createOAuthHandlers.ts +++ b/plugins/auth-node/src/oauth/createOAuthHandlers.ts @@ -51,7 +51,7 @@ export interface OAuthHandlersOptions { providerId: string; config: Config; resolverContext: AuthResolverContext; - profileTransform: OAuthProfileTransform; + profileTransform?: OAuthProfileTransform; cookieConfigurer?: CookieConfigurer; signInResolver?: SignInResolver>; } @@ -89,7 +89,6 @@ export function createOAuthHandlers( isOriginAllowed, cookieConfigurer, resolverContext, - profileTransform, signInResolver, } = options; @@ -98,6 +97,8 @@ export function createOAuthHandlers( config.getOptionalString('callbackUrl') ?? `${baseUrl}/${providerId}/handler/frame`; + const profileTransform = + options.profileTransform ?? authenticator.defaultProfileTransform; const authenticatorCtx = authenticator.initialize({ config, callbackUrl }); const cookieManager = new OAuthCookieManager({ baseUrl,