auth-node: add default OAuth profile transform

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-07-26 17:56:44 +02:00
parent 1e5baf0c6e
commit 6f5414273c
2 changed files with 12 additions and 2 deletions
@@ -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<PassportProfile> =
async input => ({
profile: PassportHelpers.transformProfile(
input.fullProfile,
input.session.idToken,
),
});
static from(strategy: Strategy) {
return new PassportOAuthAuthenticatorHelper(strategy);
}
@@ -51,7 +51,7 @@ export interface OAuthHandlersOptions<TProfile> {
providerId: string;
config: Config;
resolverContext: AuthResolverContext;
profileTransform: OAuthProfileTransform<TProfile>;
profileTransform?: OAuthProfileTransform<TProfile>;
cookieConfigurer?: CookieConfigurer;
signInResolver?: SignInResolver<OAuthAuthenticatorResult<TProfile>>;
}
@@ -89,7 +89,6 @@ export function createOAuthHandlers<TProfile>(
isOriginAllowed,
cookieConfigurer,
resolverContext,
profileTransform,
signInResolver,
} = options;
@@ -98,6 +97,8 @@ export function createOAuthHandlers<TProfile>(
config.getOptionalString('callbackUrl') ??
`${baseUrl}/${providerId}/handler/frame`;
const profileTransform =
options.profileTransform ?? authenticator.defaultProfileTransform;
const authenticatorCtx = authenticator.initialize({ config, callbackUrl });
const cookieManager = new OAuthCookieManager({
baseUrl,