Fix Microsoft Auth Provider when Profile not requested

Ensure that the Microsoft provider passes an empty profile object down if it hasn't received/requested one from the provider.  Fixes #23032.

The legacy Microsoft provider did something similar to replace a null profile with an empty object. https://github.com/backstage/backstage/blob/96c4f54bf6070db12676e9af0bf75d0d479c3d72/plugins/auth-backend/src/providers/microsoft/provider.ts#L266

I guess the only question is whether we want to fix this specifically for the Microsoft provider, or should we handle a null profiles deeper in the stack (i.e. `PassportOAuthAuthenticatorHelper.defaultProfileTransform` or in `PassportHelpers.transformProfile`)

Reason this didn't affect the legacy backend is that it was only recently the legacy backend Microsoft module was swapped over to use the path from the newer backend - #22208

Signed-off-by: Alex Crome <afscrome@users.noreply.github.com>
This commit is contained in:
Alex Crome
2024-02-19 14:38:19 +00:00
parent 9b65b814f6
commit 71c3b7f765
2 changed files with 16 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-backend-module-microsoft-provider': patch
---
Fix error when microsoft token is requested without the profile scope.
@@ -16,6 +16,7 @@
import {
createOAuthAuthenticator,
OAuthAuthenticatorResult,
PassportOAuthAuthenticatorHelper,
PassportOAuthDoneCallback,
PassportProfile,
@@ -25,8 +26,16 @@ import { union } from 'lodash';
/** @public */
export const microsoftAuthenticator = createOAuthAuthenticator({
defaultProfileTransform:
PassportOAuthAuthenticatorHelper.defaultProfileTransform,
defaultProfileTransform: (
result: OAuthAuthenticatorResult<PassportProfile>,
context,
) => {
result.fullProfile = result.fullProfile ?? {};
return PassportOAuthAuthenticatorHelper.defaultProfileTransform(
result,
context,
);
},
initialize({ callbackUrl, config }) {
const clientId = config.getString('clientId');
const clientSecret = config.getString('clientSecret');