Skip to content

Commit 25b7690

Browse files
author
Kalyan Krishna
committed
Major update to sample
1 parent fc1c2d9 commit 25b7690

File tree

7 files changed

+260
-149
lines changed

7 files changed

+260
-149
lines changed

5-WebApp-AuthZ/5-2-Groups/AppCreationScripts/AppCreationScripts.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
```
1212
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly. (Other ways of running the scripts are described below)
1313
```PowerShell
14-
cd .\AppCreationScripts\
14+
cd .\AppCreationScripts\
1515
.\Configure.ps1
1616
```
1717
1. Open the Visual Studio solution and click start
@@ -27,6 +27,7 @@ The following paragraphs:
2727
- [Passing credentials](#option-2-non-interactive) to create the app in your home tenant
2828
- [Interactively in a specific tenant](#option-3-interactive-but-create-apps-in-a-specified-tenant)
2929
- [Passing credentials in a specific tenant](#option-4-non-interactive-and-create-apps-in-a-specified-tenant)
30+
- [Passing environment name, for Sovereign clouds](#running-the-script-on-azure-sovereign-clouds)
3031

3132
## Goal of the scripts
3233

@@ -50,7 +51,7 @@ These scripts are:
5051

5152
The `Configure.ps1` will stop if it tries to create an Azure AD application which already exists in the tenant. For this, if you are using the script to try/test the sample, or in DevOps scenarios, you might want to run `Cleanup.ps1` just before `Configure.ps1`. This is what is shown in the steps below.
5253

53-
## How to use the app creation scripts ?
54+
## How to use the app creation scripts?
5455

5556
### Pre-requisites
5657

@@ -108,7 +109,7 @@ Note that the script will choose the tenant in which to create the applications,
108109
109110
#### Option 2 (non-interactive)
110111
111-
When you know the indentity and credentials of the user in the name of whom you want to create the applications, you can use the non-interactive approach. It's more adapted to DevOps. Here is an example of script you'd want to run in a PowerShell Window
112+
When you know the identity and credentials of the user in the name of whom you want to create the applications, you can use the non-interactive approach. It's more adapted to DevOps. Here is an example of script you'd want to run in a PowerShell Window
112113
113114
```PowerShell
114115
$secpasswd = ConvertTo-SecureString "[Password here]" -AsPlainText -Force
@@ -145,3 +146,21 @@ $tenantId = "yourTenantIdGuid"
145146
. .\Cleanup.ps1 -Credential $mycreds -TenantId $tenantId
146147
. .\Configure.ps1 -Credential $mycreds -TenantId $tenantId
147148
```
149+
150+
### Running the script on Azure Sovereign clouds
151+
152+
All the four options listed above, can be used on any Azure Sovereign clouds. By default, the script targets `AzureCloud`, but it can be changed using the parameter `-AzureEnvironmentName`.
153+
154+
The acceptable values for this parameter are:
155+
156+
- AzureCloud
157+
- AzureChinaCloud
158+
- AzureUSGovernment
159+
- AzureGermanyCloud
160+
161+
Example:
162+
163+
```PowerShell
164+
. .\Cleanup.ps1 -AzureEnvironmentName "AzureGermanyCloud"
165+
. .\Configure.ps1 -AzureEnvironmentName "AzureGermanyCloud"
166+
```

5-WebApp-AuthZ/5-2-Groups/AppCreationScripts/Cleanup.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
param(
33
[PSCredential] $Credential,
44
[Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5-
[string] $tenantId
5+
[string] $tenantId,
6+
[Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
7+
[string] $azureEnvironmentName
68
)
79

810
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
@@ -13,10 +15,15 @@ $ErrorActionPreference = "Stop"
1315

1416
Function Cleanup
1517
{
16-
<#
17-
.Description
18-
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
19-
#>
18+
if (!$azureEnvironmentName)
19+
{
20+
$azureEnvironmentName = "AzureCloud"
21+
}
22+
23+
<#
24+
.Description
25+
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
26+
#>
2027

2128
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
2229
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -25,17 +32,17 @@ This function removes the Azure AD applications for the sample. These applicatio
2532
# you'll need to sign-in with creds enabling your to create apps in the tenant)
2633
if (!$Credential -and $TenantId)
2734
{
28-
$creds = Connect-AzureAD -TenantId $tenantId
35+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
2936
}
3037
else
3138
{
3239
if (!$TenantId)
3340
{
34-
$creds = Connect-AzureAD -Credential $Credential
41+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3542
}
3643
else
3744
{
38-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
45+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3946
}
4047
}
4148

5-WebApp-AuthZ/5-2-Groups/AppCreationScripts/Configure.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
param(
33
[PSCredential] $Credential,
44
[Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5-
[string] $tenantId
5+
[string] $tenantId,
6+
[Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
7+
[string] $azureEnvironmentName
68
)
79

810
<#
@@ -147,6 +149,11 @@ Function ConfigureApplications
147149
so that they are consistent with the Applications parameters
148150
#>
149151
$commonendpoint = "common"
152+
153+
if (!$azureEnvironmentName)
154+
{
155+
$azureEnvironmentName = "AzureCloud"
156+
}
150157

151158
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
152159
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -155,17 +162,17 @@ Function ConfigureApplications
155162
# you'll need to sign-in with creds enabling your to create apps in the tenant)
156163
if (!$Credential -and $TenantId)
157164
{
158-
$creds = Connect-AzureAD -TenantId $tenantId
165+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
159166
}
160167
else
161168
{
162169
if (!$TenantId)
163170
{
164-
$creds = Connect-AzureAD -Credential $Credential
171+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
165172
}
166173
else
167174
{
168-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
175+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
169176
}
170177
}
171178

@@ -174,6 +181,8 @@ Function ConfigureApplications
174181
$tenantId = $creds.Tenant.Id
175182
}
176183

184+
185+
177186
$tenant = Get-AzureADTenantDetail
178187
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
179188

@@ -223,7 +232,7 @@ Function ConfigureApplications
223232
# Add Required Resources Access (from 'webApp' to 'Microsoft Graph')
224233
Write-Host "Getting access from 'webApp' to 'Microsoft Graph'"
225234
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
226-
-requiredDelegatedPermissions "User.Read|Directory.Read.All" `
235+
-requiredDelegatedPermissions "GroupMember.Read.All" `
227236

228237
$requiredResourcesAccess.Add($requiredPermissions)
229238

5-WebApp-AuthZ/5-2-Groups/AppCreationScripts/Quickstart.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
"Sample": {
7-
"Title": "Add authorization using groups & group claims to an ASP.NET Core Web app thats signs-in users with the Microsoft identity platform",
7+
"Title": "Add authorization using groups & group claims to an ASP.NET Core Web app that signs-in users with the Microsoft identity platform",
88
"Level": 400,
99
"Client": "ASP.NET Core Web App"
1010
},

5-WebApp-AuthZ/5-2-Groups/AppCreationScripts/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"RequiredResourcesAccess": [
2626
{
2727
"Resource": "Microsoft Graph",
28-
"DelegatedPermissions": [ "User.Read", "Directory.Read.All" ]
28+
"DelegatedPermissions": [ "GroupMember.Read.All" ]
2929
}
3030
]
3131
}

0 commit comments

Comments
 (0)