From 327c3f01eb3d321f00e0024a74abcf966bf95d25 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 Apr 2022 15:12:14 +0200 Subject: [PATCH] auth-backend: migrate microsoft sign-in resolver Signed-off-by: Patrik Oldsberg --- .../src/providers/microsoft/provider.ts | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/plugins/auth-backend/src/providers/microsoft/provider.ts b/plugins/auth-backend/src/providers/microsoft/provider.ts index 106ab66b6d..bbb4afae40 100644 --- a/plugins/auth-backend/src/providers/microsoft/provider.ts +++ b/plugins/auth-backend/src/providers/microsoft/provider.ts @@ -186,23 +186,6 @@ export class MicrosoftAuthProvider implements OAuthHandlers { } } -export const microsoftEmailSignInResolver: SignInResolver = async ( - info, - ctx, -) => { - const { profile } = info; - - if (!profile.email) { - throw new Error('Microsoft profile contained no email'); - } - - return ctx.signInWithCatalogUser({ - annotations: { - 'microsoft.com/email': profile.email, - }, - }); -}; - /** * @deprecated This type has been inlined into the create method and will be removed. */ @@ -285,6 +268,26 @@ export const microsoft = createAuthProviderIntegration({ }); }); }, + resolvers: { + /** + * Looks up the user by matching their email to the `microsoft.com/email` annotation. + */ + lookupEmailAnnotation(): SignInResolver { + return async (info, ctx) => { + const { profile } = info; + + if (!profile.email) { + throw new Error('Microsoft profile contained no email'); + } + + return ctx.signInWithCatalogUser({ + annotations: { + 'microsoft.com/email': profile.email, + }, + }); + }; + }, + }, }); /** @@ -292,3 +295,10 @@ export const microsoft = createAuthProviderIntegration({ * @deprecated Use `providers.microsoft.create` instead */ export const createMicrosoftProvider = microsoft.create; + +/** + * @public + * @deprecated Use `providers.microsoft.resolvers.lookupEmailAnnotation()` instead. + */ +export const microsoftEmailSignInResolver = + microsoft.resolvers.lookupEmailAnnotation();