From d7def5d0cb1d6ef630b73323aca1b49e4ab82c3b Mon Sep 17 00:00:00 2001 From: Alex Crome Date: Wed, 25 Oct 2023 21:49:23 +0100 Subject: [PATCH] PR Feedback * Tidy up passing of domain hint from initalisation to later methods * Tidy up change set Signed-off-by: Alex Crome --- .changeset/gentle-pumpkins-carry.md | 15 ++--------- .../src/authenticator.ts | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/.changeset/gentle-pumpkins-carry.md b/.changeset/gentle-pumpkins-carry.md index 22abd16798..721fbe8195 100644 --- a/.changeset/gentle-pumpkins-carry.md +++ b/.changeset/gentle-pumpkins-carry.md @@ -1,16 +1,5 @@ --- -'@backstage/plugin-auth-backend-module-microsoft-provider': minor +'@backstage/plugin-auth-backend-module-microsoft-provider': patch --- -Added support for specifying a `domain_hint` on Microsoft authentication provider configuration. -This should typically be set to the same value as your `tenantId`. -If you allow users from multiple tenants to authenticate, then leave this blank. - -```yaml -auth: - providers: - microsoft: - development: - #... - domainHint: ${AZURE_TENANT_ID} -``` +Added support for specifying a domain hint on the Microsoft authentication provider configuration. diff --git a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts index edf985b0f2..9687c7ce1a 100644 --- a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts @@ -22,8 +22,6 @@ import { PassportProfile, } from '@backstage/plugin-auth-node'; -let domainHint: string | undefined = undefined; - /** @public */ export const microsoftAuthenticator = createOAuthAuthenticator({ defaultProfileTransform: @@ -32,9 +30,9 @@ export const microsoftAuthenticator = createOAuthAuthenticator({ const clientId = config.getString('clientId'); const clientSecret = config.getString('clientSecret'); const tenantId = config.getString('tenantId'); - domainHint = config.getOptionalString('domainHint'); + const domainHint = config.getOptionalString('domainHint'); - return PassportOAuthAuthenticatorHelper.from( + const helper = PassportOAuthAuthenticatorHelper.from( new MicrosoftStrategy( { clientID: clientId, @@ -58,25 +56,30 @@ export const microsoftAuthenticator = createOAuthAuthenticator({ }, ), ); + + return { + helper, + domainHint, + }; }, - async start(input, helper) { + async start(input, ctx) { const options: Record = { accessType: 'offline', }; - if (domainHint !== undefined) { - options.domain_hint = domainHint; + if (ctx.domainHint !== undefined) { + options.domain_hint = ctx.domainHint; } - return helper.start(input, options); + return ctx.helper.start(input, options); }, - async authenticate(input, helper) { - return helper.authenticate(input); + async authenticate(input, ctx) { + return ctx.helper.authenticate(input); }, - async refresh(input, helper) { - return helper.refresh(input); + async refresh(input, ctx) { + return ctx.helper.refresh(input); }, });