From ee08d32106dfa004055f1f14b133ed4299e5a3e1 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 Apr 2022 14:56:24 +0200 Subject: [PATCH] auth-backend: update google provider to match other providers Signed-off-by: Patrik Oldsberg --- .../src/providers/google/provider.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index 10187c4d97..bc05104ec6 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -17,7 +17,6 @@ import express from 'express'; import passport from 'passport'; import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; -import { getEntityClaims } from '../../lib/catalog'; import { encodeState, OAuthAdapter, @@ -189,6 +188,11 @@ export type GoogleProviderOptions = { }; }; +/** + * Auth provider integration for Google auth + * + * @public + */ export const google = createAuthProviderIntegration({ create(options?: { /** @@ -239,7 +243,13 @@ export const google = createAuthProviderIntegration({ }); }, resolvers: { + /** + * Looks up the user by matching their email local part to the entity name. + */ byEmailLocalPart: () => commonByEmailLocalPartResolver, + /** + * Looks up the user by matching their email to the `google.com/email` annotation. + */ lookupEmailAnnotation(): SignInResolver { return async (info, ctx) => { const { profile } = info; @@ -248,27 +258,25 @@ export const google = createAuthProviderIntegration({ throw new Error('Google profile contained no email'); } - const entity = await ctx.catalogIdentityClient.findUser({ + return ctx.signInWithCatalogUser({ annotations: { 'google.com/email': profile.email, }, }); - - const claims = getEntityClaims(entity); - const token = await ctx.tokenIssuer.issueToken({ claims }); - - return { id: entity.metadata.name, entity, token }; }; }, }, }); /** + * @public * @deprecated Use `providers.google.create` instead. */ export const createGoogleProvider = google.create; /** - * @deprecated Use `google.resolvers.lookupEmailAnnotation` instead. + * @public + * @deprecated Use `providers.google.resolvers.lookupEmailAnnotation()` instead. */ -export const googleEmailSignInResolver = google.resolvers.lookupEmailAnnotation; +export const googleEmailSignInResolver = + google.resolvers.lookupEmailAnnotation();