diff --git a/docs/auth/microsoft/provider.md b/docs/auth/microsoft/provider.md index 46da74cc31..245e3ffe75 100644 --- a/docs/auth/microsoft/provider.md +++ b/docs/auth/microsoft/provider.md @@ -28,7 +28,7 @@ On the **API permissions** tab, click on `Add Permission`, then add the followin - `openid` - `profile` - `User.Read` -- Optional custom permissions you defined in the configuration file +- Optional custom scopes you defined in the app-config.yaml file. Your company may require you to grant [admin consent](https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/user-admin-consent-overview) for these permissions. Even if your company doesn't require admin consent, you may wish to do so as it means users don't need to individually consent the first time they access backstage. diff --git a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts index 93058b7eec..1b6eb87fae 100644 --- a/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-microsoft-provider/src/authenticator.ts @@ -21,7 +21,7 @@ import { PassportProfile, } from '@backstage/plugin-auth-node'; import { ExtendedMicrosoftStrategy } from './strategy'; -import { scopeHelper } from './scopes'; +import { union } from 'lodash'; /** @public */ export const microsoftAuthenticator = createOAuthAuthenticator({ @@ -32,7 +32,7 @@ export const microsoftAuthenticator = createOAuthAuthenticator({ const clientSecret = config.getString('clientSecret'); const tenantId = config.getString('tenantId'); const domainHint = config.getOptionalString('domainHint'); - const scope = scopeHelper( + const scope = union( ['user.read'], config.getOptionalStringArray('additionalScopes'), ); diff --git a/plugins/auth-backend-module-microsoft-provider/src/scopes.test.ts b/plugins/auth-backend-module-microsoft-provider/src/scopes.test.ts deleted file mode 100644 index 412f87a601..0000000000 --- a/plugins/auth-backend-module-microsoft-provider/src/scopes.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { scopeHelper } from './scopes'; - -describe('microsoftScopeHelper', () => { - it('default scope only with undefined additional scopes', () => { - const scopeResult = scopeHelper(['default']); - expect(scopeResult.length).toBe(1); - expect(scopeResult).toEqual(expect.arrayContaining(['default'])); - }); - - it('default scope only with empty additional scopes', () => { - const scopeResult = scopeHelper(['default'], []); - expect(scopeResult.length).toBe(1); - expect(scopeResult).toEqual(expect.arrayContaining(['default'])); - }); - - it('default scope with mutually exclusive additional scopes', () => { - const scopeResult = scopeHelper(['default'], ['secondScope', 'thirdScope']); - expect(scopeResult.length).toBe(3); - expect(scopeResult).toEqual( - expect.arrayContaining(['default', 'secondScope', 'thirdScope']), - ); - }); - - it('default scope with overlapping additional scopes', () => { - const scopeResult = scopeHelper( - ['default', 'secondScope'], - ['default', 'secondScope', 'thirdScope'], - ); - expect(scopeResult.length).toBe(3); - expect(scopeResult).toEqual( - expect.arrayContaining(['default', 'secondScope', 'thirdScope']), - ); - }); -}); diff --git a/plugins/auth-backend-module-microsoft-provider/src/scopes.ts b/plugins/auth-backend-module-microsoft-provider/src/scopes.ts deleted file mode 100644 index f70f69c01f..0000000000 --- a/plugins/auth-backend-module-microsoft-provider/src/scopes.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Combine two arrays of scopes without duplicates - * @param defaultScopes Default scopes - * @param additionalScopes Optional additional scopes - * @returns List of scopes - * @public - */ -export const scopeHelper = ( - defaultScopes: string[], - additionalScopes?: string[], -): string[] => { - const scope: string[] = defaultScopes.concat(additionalScopes || []); - return scope.filter((value, index) => scope.indexOf(value) === index); -};