|
| 1 | +extension microsoftGraphV1 |
| 2 | + |
| 3 | +@description('Specifies the name of cloud environment to run this deployment in.') |
| 4 | +param cloudEnvironment string = environment().name |
| 5 | + |
| 6 | +// NOTE: Microsoft Graph Bicep file deployment is only supported in Public Cloud |
| 7 | +@description('Audience uris for public and national clouds') |
| 8 | +param audiences object = { |
| 9 | + AzureCloud: { |
| 10 | + uri: 'api://AzureADTokenExchange' |
| 11 | + } |
| 12 | + AzureUSGovernment: { |
| 13 | + uri: 'api://AzureADTokenExchangeUSGov' |
| 14 | + } |
| 15 | + USNat: { |
| 16 | + uri: 'api://AzureADTokenExchangeUSNat' |
| 17 | + } |
| 18 | + USSec: { |
| 19 | + uri: 'api://AzureADTokenExchangeUSSec' |
| 20 | + } |
| 21 | + AzureChinaCloud: { |
| 22 | + uri: 'api://AzureADTokenExchangeChina' |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +@description('Specifies the ID of the user-assigned managed identity.') |
| 27 | +param webAppIdentityId string |
| 28 | + |
| 29 | +@description('Specifies the unique name for the client application.') |
| 30 | +param clientAppName string |
| 31 | + |
| 32 | +@description('Specifies the display name for the client application') |
| 33 | +param clientAppDisplayName string |
| 34 | + |
| 35 | +@description('Specifies the scopes that the client application requires.') |
| 36 | +param clientAppScopes array = ['User.Read', 'offline_access', 'openid', 'profile'] |
| 37 | + |
| 38 | +param serviceManagementReference string = '' |
| 39 | + |
| 40 | +param issuer string |
| 41 | + |
| 42 | +param webAppEndpoint string |
| 43 | + |
| 44 | +// Get the MS Graph Service Principal based on its application ID: |
| 45 | +// https://learn.microsoft.com/troubleshoot/entra/entra-id/governance/verify-first-party-apps-sign-in |
| 46 | +var msGraphAppId = '00000003-0000-0000-c000-000000000000' |
| 47 | +resource msGraphSP 'Microsoft.Graph/[email protected]' existing = { |
| 48 | + appId: msGraphAppId |
| 49 | +} |
| 50 | + |
| 51 | +var graphScopes = msGraphSP.oauth2PermissionScopes |
| 52 | +resource clientApp 'Microsoft.Graph/[email protected]' = { |
| 53 | + uniqueName: clientAppName |
| 54 | + displayName: clientAppDisplayName |
| 55 | + signInAudience: 'AzureADMyOrg' |
| 56 | + serviceManagementReference: empty(serviceManagementReference) ? null : serviceManagementReference |
| 57 | + web: { |
| 58 | + redirectUris: [ |
| 59 | + 'http://localhost:50505/.auth/login/aad/callback' |
| 60 | + '${webAppEndpoint}/.auth/login/aad/callback' |
| 61 | + ] |
| 62 | + implicitGrantSettings: { enableIdTokenIssuance: true } |
| 63 | + } |
| 64 | + requiredResourceAccess: [ |
| 65 | + { |
| 66 | + resourceAppId: msGraphAppId |
| 67 | + resourceAccess: [ |
| 68 | + for (scope, i) in clientAppScopes: { |
| 69 | + id: filter(graphScopes, graphScopes => graphScopes.value == scope)[0].id |
| 70 | + type: 'Scope' |
| 71 | + } |
| 72 | + ] |
| 73 | + } |
| 74 | + ] |
| 75 | + |
| 76 | + resource clientAppFic '[email protected]' = { |
| 77 | + name: '${clientApp.uniqueName}/miAsFic' |
| 78 | + audiences: [ |
| 79 | + audiences[cloudEnvironment].uri |
| 80 | + ] |
| 81 | + issuer: issuer |
| 82 | + subject: webAppIdentityId |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +resource clientSp 'Microsoft.Graph/[email protected]' = { |
| 87 | + appId: clientApp.appId |
| 88 | +} |
| 89 | + |
| 90 | +output clientAppId string = clientApp.appId |
| 91 | +output clientSpId string = clientSp.id |
0 commit comments