Use loadash instead of own implementation and fixed documentation.
Signed-off-by: Daniel Doberenz <daniel.doberenz@lichtblick.de>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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'),
|
||||
);
|
||||
|
||||
@@ -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']),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user