From a0b01eda2cbd5201ae04083ceec2f94e63548dfa Mon Sep 17 00:00:00 2001 From: Alex Crome Date: Mon, 19 Feb 2024 15:07:42 +0000 Subject: [PATCH] Moved defence against null tokens into `defaultProfileTransform` to apply more broadly than just Microsoft tokens. Signed-off-by: Alex Crome --- .changeset/eight-oranges-wave.md | 2 +- .../src/authenticator.ts | 12 ++---------- .../src/oauth/PassportOAuthAuthenticatorHelper.ts | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.changeset/eight-oranges-wave.md b/.changeset/eight-oranges-wave.md index 348795447e..e0618e5de0 100644 --- a/.changeset/eight-oranges-wave.md +++ b/.changeset/eight-oranges-wave.md @@ -2,4 +2,4 @@ '@backstage/plugin-auth-backend-module-microsoft-provider': patch --- -Fix error when Microsoft token is requested without the profile scope. +Fix error when Microsoft tokens (or any other using the `defaultProfileTransform`) are requested without the profile scope. diff --git a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts index f4927b76c0..cc8f820afd 100644 --- a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts @@ -26,16 +26,8 @@ import { union } from 'lodash'; /** @public */ export const microsoftAuthenticator = createOAuthAuthenticator({ - defaultProfileTransform: ( - result: OAuthAuthenticatorResult, - context, - ) => { - result.fullProfile = result.fullProfile ?? {}; - return PassportOAuthAuthenticatorHelper.defaultProfileTransform( - result, - context, - ); - }, + defaultProfileTransform: + PassportOAuthAuthenticatorHelper.defaultProfileTransform, initialize({ callbackUrl, config }) { const clientId = config.getString('clientId'); const clientSecret = config.getString('clientSecret'); diff --git a/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts b/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts index 420a661da5..c03a9cb56f 100644 --- a/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts +++ b/plugins/auth-node/src/oauth/PassportOAuthAuthenticatorHelper.ts @@ -57,7 +57,7 @@ export class PassportOAuthAuthenticatorHelper { OAuthAuthenticatorResult > = async input => ({ profile: PassportHelpers.transformProfile( - input.fullProfile, + input.fullProfile ?? {}, input.session.idToken, ), });