auth-node: add default OAuth profile transform
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user