Merge pull request #21274 from LichtBlick-PENG-Daniel/Extend-microsoft-auth-provider

Added the possibility to use custom scopes for Microsoft Auth Plugin
This commit is contained in:
Patrik Oldsberg
2024-01-21 14:15:40 +01:00
committed by GitHub
8 changed files with 21 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-backend-module-microsoft-provider': patch
---
Added the possibility to use custom scopes for performing login with Microsoft EntraID.
+4
View File
@@ -28,6 +28,7 @@ On the **API permissions** tab, click on `Add Permission`, then add the followin
- `openid`
- `profile`
- `User.Read`
- Optional custom scopes of the `Microsoft Graph` API 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.
@@ -54,6 +55,8 @@ auth:
clientSecret: ${AZURE_CLIENT_SECRET}
tenantId: ${AZURE_TENANT_ID}
domainHint: ${AZURE_TENANT_ID}
additionalScopes:
- Mail.Send
```
The Microsoft provider is a structure with three mandatory configuration keys:
@@ -65,6 +68,7 @@ The Microsoft provider is a structure with three mandatory configuration keys:
Leave blank if your app registration is multi tenant.
When specified, this reduces login friction for users with accounts in multiple tenants by automatically filtering away accounts from other tenants.
For more details, see [Home Realm Discovery](https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/home-realm-discovery-policy)
- `additionalScopes` (optional): List of scopes for the App Registration. The default and mandatory value is ['user.read'].
## Adding the provider to the Backstage frontend
@@ -28,6 +28,7 @@ export interface Config {
clientSecret: string;
domainHint?: string;
callbackUrl?: string;
additionalScopes?: string[];
};
};
};
@@ -27,6 +27,7 @@
"@backstage/plugin-auth-node": "workspace:^",
"express": "^4.18.2",
"jose": "^4.6.0",
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"passport": "^0.7.0",
"passport-microsoft": "^1.0.0"
@@ -113,6 +113,7 @@ describe('microsoftAuthenticator', () => {
tenantId: 'tenantId',
clientId: 'clientId',
clientSecret: 'clientSecret',
additionalScopes: ['User.Read.All'],
}),
});
});
@@ -21,6 +21,7 @@ import {
PassportProfile,
} from '@backstage/plugin-auth-node';
import { ExtendedMicrosoftStrategy } from './strategy';
import { union } from 'lodash';
/** @public */
export const microsoftAuthenticator = createOAuthAuthenticator({
@@ -31,6 +32,10 @@ export const microsoftAuthenticator = createOAuthAuthenticator({
const clientSecret = config.getString('clientSecret');
const tenantId = config.getString('tenantId');
const domainHint = config.getOptionalString('domainHint');
const scope = union(
['user.read'],
config.getOptionalStringArray('additionalScopes'),
);
const helper = PassportOAuthAuthenticatorHelper.from(
new ExtendedMicrosoftStrategy(
@@ -39,7 +44,7 @@ export const microsoftAuthenticator = createOAuthAuthenticator({
clientSecret: clientSecret,
callbackURL: callbackUrl,
tenant: tenantId,
scope: ['user.read'],
scope: scope,
},
(
accessToken: string,
@@ -38,6 +38,7 @@ describe('authModuleMicrosoftProvider', () => {
clientId: 'my-client-id',
clientSecret: 'my-client-secret',
tenantId: 'my-tenant-id',
additionalScopes: ['User.Read.All'],
},
},
},
@@ -66,7 +67,7 @@ describe('authModuleMicrosoftProvider', () => {
expect(startUrl.pathname).toBe('/my-tenant-id/oauth2/v2.0/authorize');
expect(Object.fromEntries(startUrl.searchParams)).toEqual({
response_type: 'code',
scope: 'user.read',
scope: 'user.read User.Read.All',
client_id: 'my-client-id',
redirect_uri: `http://localhost:${server.port()}/api/auth/microsoft/handler/frame`,
state: expect.any(String),
+1
View File
@@ -4636,6 +4636,7 @@ __metadata:
"@types/passport-microsoft": ^1.0.0
express: ^4.18.2
jose: ^4.6.0
lodash: ^4.17.21
msw: ^1.0.0
node-fetch: ^2.6.7
passport: ^0.7.0