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,