From 9f03434cfbf36d176a80e0917903a675c0ed134a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 Apr 2022 15:18:41 +0200 Subject: [PATCH] auth-backend: migrate saml sign-in resolver Signed-off-by: Patrik Oldsberg --- .../src/providers/saml/provider.ts | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/plugins/auth-backend/src/providers/saml/provider.ts b/plugins/auth-backend/src/providers/saml/provider.ts index 3009b6bedf..3f4b7a960d 100644 --- a/plugins/auth-backend/src/providers/saml/provider.ts +++ b/plugins/auth-backend/src/providers/saml/provider.ts @@ -130,20 +130,6 @@ export class SamlAuthProvider implements AuthProviderRouteHandlers { } } -export const samlNameIdEntityNameSignInResolver: SignInResolver< - SamlAuthResult -> = async (info, ctx) => { - const id = info.result.fullProfile.nameID; - - if (!id) { - throw new AuthenticationError('No nameID found in SAML response'); - } - - return ctx.signInWithCatalogUser({ - entityRef: { name: id }, - }); -}; - type SignatureAlgorithm = 'sha1' | 'sha256' | 'sha512'; /** @@ -224,6 +210,24 @@ export const saml = createAuthProviderIntegration({ }); }; }, + resolvers: { + /** + * Looks up the user by matching their nameID to the entity name. + */ + byNameId(): SignInResolver { + return async (info, ctx) => { + const id = info.result.fullProfile.nameID; + + if (!id) { + throw new AuthenticationError('No nameID found in SAML response'); + } + + return ctx.signInWithCatalogUser({ + entityRef: { name: id }, + }); + }; + }, + }, }); /** @@ -231,3 +235,9 @@ export const saml = createAuthProviderIntegration({ * @deprecated Use `providers.saml.create` instead */ export const createSamlProvider = saml.create; + +/** + * @public + * @deprecated Use `providers.saml.resolvers.byNameId()` instead. + */ +export const samlNameIdEntityNameSignInResolver = saml.resolvers.byNameId();