0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-04-07 23:01:25 -05:00

chore: add scopes field to MS Azure AD connector (#7087)

* chore: add scopes field to MS Axure AD connector

* fix: fix scopes
This commit is contained in:
Darcy Ye 2025-03-20 21:13:23 -07:00 committed by GitHub
parent e11cb003dc
commit 9b6dbf28e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"@logto/connector-azuread": patch
---
add `scopes` configuration field for Microsoft Azure AD connector

View file

@ -12,6 +12,7 @@ The Microsoft Azure AD connector provides a succinct way for your application to
- [Cloud Instance](#cloud-instance)
- [Tenant ID](#tenant-id)
- [Prompts](#prompts)
- [Scopes](#scopes)
- [References](#references)
## Set up Microsoft Azure AD in the Azure Portal
@ -31,6 +32,7 @@ The Microsoft Azure AD connector provides a succinct way for your application to
| tenantId | string |
| cloudInstance | string |
| prompts | string[] |
| scopes | string? |
### Client ID
@ -66,6 +68,12 @@ The `prompts` field is an array of strings that specifies the type of user inter
Logto will concatenate the prompts with a space as the value of `prompt` in the authorization URL.
### Scopes
The `scopes` field is a space-separated list of scopes the application needs. The list of scopes can be found in the [Microsoft Graph permissions reference](https://learn.microsoft.com/en-us/graph/permissions-reference).
The default scopes are `User.Read`, leave this field empty unless you need other scopes.
## References
- [Web app that signs in users](https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-sign-user-overview)

View file

@ -62,6 +62,13 @@ export const defaultMetadata: ConnectorMetadata = {
value: prompt,
})),
},
{
key: 'scopes',
type: ConnectorConfigFormItemType.Text,
required: false,
label: 'Scopes',
placeholder: '<scope1> <scope2>',
},
],
};

View file

@ -1,4 +1,4 @@
import { assert, conditional } from '@silverhand/essentials';
import { assert, conditional, deduplicate } from '@silverhand/essentials';
import { got, HTTPError } from 'got';
import path from 'node:path';
@ -19,7 +19,12 @@ import {
parseJson,
} from '@logto/connector-kit';
import { scopes, defaultMetadata, defaultTimeout, graphAPIEndpoint } from './constant.js';
import {
scopes as defaultScopes,
defaultMetadata,
defaultTimeout,
graphAPIEndpoint,
} from './constant.js';
import type { AzureADConfig } from './types.js';
import {
azureADConfigGuard,
@ -37,10 +42,10 @@ const getAuthorizationUri =
const config = await getConfig(defaultMetadata.id);
validateConfig(config, azureADConfigGuard);
const { clientId, clientSecret, cloudInstance, tenantId, prompts } = config;
const { clientId, clientSecret, cloudInstance, tenantId, prompts, scopes } = config;
const defaultAuthCodeUrlParameters: AuthorizationUrlRequest = {
scopes,
scopes: deduplicate([...defaultScopes, ...(scopes?.split(' ') ?? [])]),
state,
redirectUri,
...conditional(prompts && prompts.length > 0 && { prompt: prompts.join(' ') }),

View file

@ -8,6 +8,7 @@ export const azureADConfigGuard = z.object({
cloudInstance: z.string(),
tenantId: z.string(),
prompts: oidcPromptsGuard,
scopes: z.string().optional(),
});
export type AzureADConfig = z.infer<typeof azureADConfigGuard>;