-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredential-manager.bicep
More file actions
75 lines (64 loc) · 2.64 KB
/
credential-manager.bicep
File metadata and controls
75 lines (64 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//=============================================================================
// Credential Manager
//
// This configuration is placed in a separate module so that we can pass in
// the client secret using: keyVault.getSecret('client-secret')
//=============================================================================
//=============================================================================
// Parameters
//=============================================================================
@description('The name of the API Management service')
param apiManagementServiceName string
@description('The OAuth target resource for which a JWT token is requested by the APIM managed identity')
param oauthTargetResource string
@description('The ID of the client used for connecting to the protected backend.')
param clientId string
@description('The secret of the client used for connecting to the protected backend.')
@secure()
param clientSecret string
//=============================================================================
// Existing resources
//=============================================================================
resource apiManagementService 'Microsoft.ApiManagement/service@2024-10-01-preview' existing = {
name: apiManagementServiceName
}
//=============================================================================
// Resources
//=============================================================================
// Create a Credential Provider that will be used to retrieve the access token for the protected backend.
resource credentialProvider 'Microsoft.ApiManagement/service/authorizationProviders@2024-10-01-preview' = {
parent: apiManagementService
name: 'credential-provider'
properties: {
displayName: 'Credential Provider'
identityProvider: 'aad'
oauth2: {
grantTypes: {
clientCredentials: {
resourceUri: oauthTargetResource
tenantId: subscription().tenantId
}
}
}
}
// Add a connection to the Credential Provider for our client
resource clientConnection 'authorizations' = {
name: 'client-connection'
properties: {
authorizationType: 'OAuth2'
oauth2grantType: 'ClientCredentials'
parameters: {
clientId: clientId
clientSecret: clientSecret
}
}
// Give the system-assigned managed identity of API Management permission to use the connection
resource accessPolicies 'accessPolicies' = {
name: 'client-connection-access-policy-apim-managed-identity'
properties: {
objectId: apiManagementService.identity.principalId
tenantId: apiManagementService.identity.tenantId
}
}
}
}