Skip to content

Commit 429b863

Browse files
authored
Merge pull request #225 from microsoftgraph/dkershaw10-updateSamples-0.1.10
Sample updates for v0.2.0 release
2 parents 3877a53 + 6b0048f commit 429b863

File tree

12 files changed

+69
-24
lines changed

12 files changed

+69
-24
lines changed

quickstart-templates/apps-permissions-and-grants/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ This sample operates in two modes, depending on the `mode` parameter.
2525

2626
The `appScopes` array parameter allows the deployer to select the Microsoft Graph Oauth2.0 scopes to set for or grant to the client application. The sample validates the set of provided scopes in the array parameter against [Microsoft Graph delegated permission scopes][graph-permissions]. Any invalid scopes provided are ignored. `appScores` should contain a list of scope names (for example *User.Read.All* and *Group.ReadWrite.All*).
2727

28+
The sample also enables the deployer to set an owner of the client application, using the `userUPN` parameter.
29+
2830
### Prerequisites
2931

3032
- A valid **Azure subscription**: If you don't own an Azure subscription, [create a free account](https://azure.microsoft.com/free/) before you begin.
3133
- An **Azure resource group** that you own under a valid Azure subscription, or [deploy without an Azure subscription][no-azure-sub].
32-
- [Bicep tools for authoring and deployment](https://learn.microsoft.com/graph/templates/quickstart-install-bicep-tools). The minimum required Bicep version is v0.30.3.
34+
- [Bicep tools for authoring and deployment](https://learn.microsoft.com/graph/templates/quickstart-install-bicep-tools). The minimum required Bicep version is v0.32.4.
3335
- Have the requisite **Microsoft Entra roles** to deploy this template:
3436

3537
- Permissions to create applications. [Users have this permission by default](https://learn.microsoft.com/entra/fundamentals/users-default-permissions#compare-member-and-guest-default-permissions). However, [admins can turn off this default](https://learn.microsoft.com/entra/fundamentals/users-default-permissions#restrict-member-users-default-permissions) in which case you need to be assigned at least the [Application Developer](https://learn.microsoft.com/entra/identity/role-based-access-control/permissions-reference#application-developer) role.

quickstart-templates/apps-permissions-and-grants/appGrantScopes.bicep

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ extension microsoftGraphV1
33
// TEMPLATE DESCRIPTION
44
/* Grant OAuth2.0 scopes to a client application definition,
55
where the target resource used is Microsoft Graph, and the deployer can select which
6-
Microsoft Graph OAuth2.0 scopes are granted on the client app.
6+
Microsoft Graph OAuth2.0 scopes are granted on the client app. The template also
7+
assigns an owner to the application and service principal.
78
89
NOTE: Setting requiredResourceAccess on a client application is NOT required
910
to grant OAuth2.0 permissions to the client application.
@@ -13,22 +14,34 @@ param date string
1314
param displayName string?
1415
param filteredScopes array
1516
param graphSpId string
17+
param userUPN string?
1618

1719
var app = 'myApp'
1820

1921
// convert scopes array into space separate scopes string
2022
var scopeArray = [for (scopeItem,i) in filteredScopes: filteredScopes[i].value]
2123
var scopeString = join(scopeArray, ' ')
2224

25+
// fetch the user's ID based on their UPN
26+
resource userOwner 'Microsoft.Graph/[email protected]' existing = if (!empty(userUPN)) {
27+
userPrincipalName: userUPN!
28+
}
29+
2330
// create basic app
2431
resource myApp 'Microsoft.Graph/[email protected]' = {
2532
displayName: displayName == null ? '${app}-${date}' :'${displayName}-${app}-${date}'
2633
uniqueName: uniqueString(app, date)
34+
owners: {
35+
relationships: (!empty(userUPN)) ? [userOwner.id] : []
36+
}
2737
}
2838

2939
// Create service principal for the basic app
3040
resource mySP 'Microsoft.Graph/[email protected]' = {
3141
appId: myApp.appId
42+
owners: {
43+
relationships: (!empty(userUPN)) ? [userOwner.id] : []
44+
}
3245
}
3346

3447
// Grant the OAuth2.0 scopes (requested in parameters) to the basic app,
@@ -44,5 +57,6 @@ resource graphScopesAssignment 'Microsoft.Graph/[email protected]' =
4457
output appName string = myApp.displayName
4558
output appObjectID string = myApp.id
4659
output appID string = myApp.appId
60+
output appOwners array = myApp.owners.relationships
4761
output scopes array = scopeArray
4862
output grantedScopes string = graphScopesAssignment.scope

quickstart-templates/apps-permissions-and-grants/appRequiredResourceAccess.bicep

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ extension microsoftGraphV1
33
// TEMPLATE DESCRIPTION
44
/* Set the required resource access on a client application definition.
55
The target resource used is Microsoft Graph, and the deployer can select which
6-
Microsoft Graph OAuth2.0 scopes are configured on the client app.
6+
Microsoft Graph OAuth2.0 scopes are configured on the client app. The template also
7+
assigns an owner to the application.
78
89
NOTE: requiredResourceAccess configures which permissions the client application
910
requires and this drives the user consent experience where permissions are granted.
@@ -13,15 +14,24 @@ extension microsoftGraphV1
1314
param date string
1415
param displayName string?
1516
param filteredScopes array
17+
param userUPN string?
1618

1719
var app = 'myApp'
1820
var graphAppId = '00000003-0000-0000-c000-000000000000'
1921

22+
// fetch the user's ID based on their UPN
23+
resource userOwner 'Microsoft.Graph/[email protected]' existing = if (!empty(userUPN)) {
24+
userPrincipalName: userUPN!
25+
}
26+
2027
// create an application with the requiredResourceAccess property
2128
// creates a resourceAccess scope for each Microsoft Graph scope in filteredScopes
2229
resource myApp 'Microsoft.Graph/[email protected]' = {
2330
displayName: displayName == null ? '${app}-${date}' :'${displayName}-${app}-${date}'
2431
uniqueName: uniqueString(app, date)
32+
owners: {
33+
relationships: (!empty(userUPN)) ? [userOwner.id] : []
34+
}
2535
requiredResourceAccess: [
2636
{
2737
resourceAppId: graphAppId
@@ -38,5 +48,6 @@ resource myApp 'Microsoft.Graph/[email protected]' = {
3848
output appName string = myApp.displayName
3949
output appObjectID string = myApp.id
4050
output appID string = myApp.appId
51+
output appOwners array = myApp.owners.relationships
4152
output scopes array = [for (scopeItem,i) in filteredScopes: filteredScopes[i].value]
4253
output clientAppResourceAccessList array = myApp.requiredResourceAccess[0].resourceAccess

quickstart-templates/apps-permissions-and-grants/bicepconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
},
55
// specify an alias for the version of the v1.0 dynamic types package you want to use
66
"extensions": {
7-
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.9-preview"
7+
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.2.0-preview"
88
}
99
}

quickstart-templates/apps-permissions-and-grants/main.bicep

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ param appScopes array = ['profile','User.Read']
2424
@allowed(['set-required-scopes','grant-scopes'])
2525
param mode string = 'set-required-scopes'
2626

27+
@description('Owner UPN for the client application')
28+
param userUPN string?
29+
30+
2731
var graphAppId = '00000003-0000-0000-c000-000000000000'
2832

2933
// Get the Microsoft Graph service principal so that the scope names
@@ -52,13 +56,15 @@ module appCreateGrantScopesModule './appGrantScopes.bicep' = if (mode == 'grant-
5256
date: date
5357
displayName: displayName
5458
graphSpId: msGraphSP.id
59+
userUPN: userUPN
5560
}
5661
}
5762

5863
// outputs
5964
output appName string = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.appName : appCreateGrantScopesModule.outputs.appName)
6065
output appObjectID string = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.appObjectID : appCreateGrantScopesModule.outputs.appObjectID)
6166
output appID string = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.appID : appCreateGrantScopesModule.outputs.appID)
67+
output appOwners array = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.appOwners : appCreateGrantScopesModule.outputs.appOwners)
6268
output foundInputScopes array = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.scopes: appCreateGrantScopesModule.outputs.scopes)
6369
output clientAppResourceAccessList array = ((mode == 'set-required-scopes') ? appCreateRraModule.outputs.clientAppResourceAccessList : ['Not set'])
6470
output grantedScopes string = ((mode == 'grant-scopes') ? appCreateGrantScopesModule.outputs.grantedScopes : 'Not set')

quickstart-templates/security-group-add-user-members/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ This template sample:
1414
1. Creates a user UPN list from a txt file.
1515
2. Creates/updates a security group with its members set based on the user UPN list
1616

17-
**NOTE:** Due to current modelling limitations [no more than 20 members can be added/updated at a time][20-members], and only [update semantics][update-only] are supported for members (and owners).
18-
1917
### Prerequisites
2018

2119
- A valid **Azure subscription**: If you don't own an Azure subscription, [create a free account](https://azure.microsoft.com/free/) before you begin.

quickstart-templates/security-group-add-user-members/bicepconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
},
55
// specify an alias for the version of the v1.0 dynamic types package you want to use
66
"extensions": {
7-
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.1.9-preview"
7+
"microsoftGraphV1": "br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:0.2.0-preview"
88
}
99
}

quickstart-templates/security-group-add-user-members/main.bicep

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
extension microsoftGraphV1
1+
// Setting replace semantics for all relationships in this template unless overridden
2+
extension microsoftGraphV1 with {
3+
relationshipSemantics: 'replace'
4+
}
5+
26

37
// TEMPLATE OVERVIEW:
48
// Creates a security group and adds the referenced users as members.
59
// The user list are in a txt file, with each user's UPN on a separate line.
610
// Replace example userlist.txt file values with user UPNs from your tenant.
11+
// The group members are added using replace semantics overwriting any
12+
// existing group members.
713

814
@description('Today\'s date used to configure a unique daily app name')
915
param date string
@@ -33,10 +39,13 @@ resource group 'Microsoft.Graph/[email protected]' = {
3339
mailNickname: uniqueString(groupName)
3440
securityEnabled: true
3541
uniqueName: groupName
36-
members: [for i in range(0, upnListLength): userList[i].id]
42+
members: {
43+
relationships: [for i in range(0, upnListLength): userList[i].id]
44+
}
3745
}
3846

3947
// outputs
4048
output addedUserList array = upnList
4149
output groupName string = group.displayName
4250
output groupId string = group.id
51+
output groupMembers array = group.members.relationships

quickstart-templates/security-group-create-with-owners-and-members/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Create a group with members and owners
22

3-
> **Note**: Minimum Bicep version required to deploy this quickstart template is [v0.30.3](https://github.com/Azure/bicep/releases/tag/v0.30.3).
3+
> **NOTE**:
4+
>
5+
> - Minimum Bicep version required to deploy this quickstart template is [v0.32.4](https://github.com/Azure/bicep/releases/tag/v0.32.4).
6+
> - This template depends on a successful deployment of [application-serviceprincipal-create-client-resource](../application-serviceprincipal-create-client-resource/)
47
5-
> **Note2**: This template depends on a successful deployment of [application-serviceprincipal-create-client-resource](../application-serviceprincipal-create-client-resource/)
8+
This template allows you to create a security group with members and owners. Both `members` and `owners` take a [MicrosoftGraphRelationship](../../generated/microsoftgraph/microsoft.graph/v1.0/0.1.10-preview/types.md#microsoftgraphrelationship) type.
69

7-
This template allows you to create a security group with members and owners. Both `members` and `owners` take a list of object ids.
8-
9-
* The resource service principal created in [application-serviceprincipal-create-client-resource](../application-serviceprincipal-create-client-resource/) is added to the owners
10-
* A managed identity is created and added to the members
10+
- The resource service principal created in [application-serviceprincipal-create-client-resource](../application-serviceprincipal-create-client-resource/) is added to the owners
11+
- A managed identity is created and added to the members
1112

1213
You can deploy the template with the following Azure CLI command (replace `<resource-group>` with the name of your resource group):
1314

0 commit comments

Comments
 (0)