From c0629e16ca7efb56f7a8083b9742480d800d4e6c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 Apr 2022 15:15:10 +0200 Subject: [PATCH] auth-backend: migrate okta sign-in resolver Signed-off-by: Patrik Oldsberg --- .../src/providers/okta/provider.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/plugins/auth-backend/src/providers/okta/provider.ts b/plugins/auth-backend/src/providers/okta/provider.ts index bbfa4d05d8..edbca32c7c 100644 --- a/plugins/auth-backend/src/providers/okta/provider.ts +++ b/plugins/auth-backend/src/providers/okta/provider.ts @@ -188,23 +188,6 @@ export class OktaAuthProvider implements OAuthHandlers { } } -export const oktaEmailSignInResolver: SignInResolver = async ( - info, - ctx, -) => { - const { profile } = info; - - if (!profile.email) { - throw new Error('Okta profile contained no email'); - } - - return ctx.signInWithCatalogUser({ - annotations: { - 'okta.com/email': profile.email, - }, - }); -}; - /** * @deprecated This type has been inlined into the create method and will be removed. */ @@ -289,6 +272,26 @@ export const okta = createAuthProviderIntegration({ }); }); }, + resolvers: { + /** + * Looks up the user by matching their email to the `okta.com/email` annotation. + */ + lookupEmailAnnotation(): SignInResolver { + return async (info, ctx) => { + const { profile } = info; + + if (!profile.email) { + throw new Error('Okta profile contained no email'); + } + + return ctx.signInWithCatalogUser({ + annotations: { + 'okta.com/email': profile.email, + }, + }); + }; + }, + }, }); /** @@ -296,3 +299,9 @@ export const okta = createAuthProviderIntegration({ * @deprecated Use `providers.okta.create` instead */ export const createOktaProvider = okta.create; + +/** + * @public + * @deprecated Use `providers.okta.resolvers.lookupEmailAnnotation()` instead. + */ +export const oktaEmailSignInResolver = okta.resolvers.lookupEmailAnnotation();