fix(auth-backend): update authhandler & signinresolver
Signed-off-by: Tom Opdebeeck <tom.opdebeeck@studiohyperdrive.be>
This commit is contained in:
@@ -132,6 +132,13 @@ describe('GitlabAuthProvider', () => {
|
||||
baseUrl: 'mock',
|
||||
catalogIdentityClient: (catalogIdentityClient as unknown) as CatalogIdentityClient,
|
||||
tokenIssuer: (tokenIssuer as unknown) as TokenIssuer,
|
||||
authHandler: async ({ fullProfile }) => ({
|
||||
profile: {
|
||||
email: fullProfile.emails![0]!.value,
|
||||
displayName: fullProfile.displayName,
|
||||
picture: 'http://gitlab.com/lols',
|
||||
},
|
||||
}),
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
for (const test of tests) {
|
||||
|
||||
@@ -58,7 +58,7 @@ type PrivateInfo = {
|
||||
export type GitlabAuthProviderOptions = OAuthProviderOptions & {
|
||||
baseUrl: string;
|
||||
signInResolver?: SignInResolver<OAuthResult>;
|
||||
authHandler?: AuthHandler<OAuthResult>;
|
||||
authHandler: AuthHandler<OAuthResult>;
|
||||
tokenIssuer: TokenIssuer;
|
||||
catalogIdentityClient: CatalogIdentityClient;
|
||||
logger: Logger;
|
||||
@@ -106,8 +106,8 @@ export class GitlabAuthProvider implements OAuthHandlers {
|
||||
this.catalogIdentityClient = options.catalogIdentityClient;
|
||||
this.logger = options.logger;
|
||||
this.tokenIssuer = options.tokenIssuer;
|
||||
this.authHandler = options.authHandler || gitlabDefaultAuthHandler;
|
||||
this.signInResolver = this.createSignInResolverFn(options);
|
||||
this.authHandler = options.authHandler;
|
||||
this.signInResolver = options.signInResolver;
|
||||
|
||||
this._strategy = new GitlabStrategy(
|
||||
{
|
||||
@@ -210,22 +210,6 @@ export class GitlabAuthProvider implements OAuthHandlers {
|
||||
return response;
|
||||
}
|
||||
|
||||
private createSignInResolverFn({
|
||||
signInResolver,
|
||||
catalogIdentityClient,
|
||||
tokenIssuer,
|
||||
logger,
|
||||
}: GitlabAuthProviderOptions): SignInResolver<OAuthResult> {
|
||||
const resolver = signInResolver || gitlabDefaultSignInResolver;
|
||||
|
||||
return info =>
|
||||
resolver(info, {
|
||||
catalogIdentityClient,
|
||||
tokenIssuer,
|
||||
logger,
|
||||
});
|
||||
}
|
||||
|
||||
private transformResult(result: OAuthResult): OAuthResult {
|
||||
const { fullProfile, ...authResult } = result;
|
||||
|
||||
@@ -295,13 +279,26 @@ export const createGitlabProvider = (
|
||||
tokenIssuer,
|
||||
});
|
||||
|
||||
const authHandler: AuthHandler<OAuthResult> =
|
||||
options?.authHandler ?? gitlabDefaultAuthHandler;
|
||||
|
||||
const signInResolverFn =
|
||||
options?.signIn?.resolver ?? gitlabDefaultSignInResolver;
|
||||
|
||||
const signInResolver: SignInResolver<OAuthResult> = info =>
|
||||
signInResolverFn(info, {
|
||||
catalogIdentityClient,
|
||||
tokenIssuer,
|
||||
logger,
|
||||
});
|
||||
|
||||
const provider = new GitlabAuthProvider({
|
||||
clientId,
|
||||
clientSecret,
|
||||
callbackUrl,
|
||||
baseUrl,
|
||||
authHandler: options?.authHandler,
|
||||
signInResolver: options?.signIn?.resolver,
|
||||
authHandler,
|
||||
signInResolver,
|
||||
catalogIdentityClient,
|
||||
logger,
|
||||
tokenIssuer,
|
||||
|
||||
Reference in New Issue
Block a user