Skip to content

Commit a73e82c

Browse files
author
Kalyan Krishna
authored
Merge pull request #343 from Azure-Samples/kkrishna/updates2020
Updates to include the new ApplicationGroups functionality
2 parents ab336d5 + cdfc5b8 commit a73e82c

File tree

15 files changed

+320
-201
lines changed

15 files changed

+320
-201
lines changed

1-WebApp-OIDC/1-2-AnyOrg/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ cd "1-WebApp-OIDC\1-2-AnyOrg"
191191

192192
2. Open your web browser and make a request to the app. Accept the IIS Express SSL certificate if needed. The app immediately attempts to authenticate you via the Microsoft identity platform endpoint. Sign in with your personal account or with work or school account.
193193

194+
> A recording of a Microsoft Identity Platform developer session that covered this topic of developing a multi-tenant app with Azure Active Directory is available at [Develop multi-tenant applications with Microsoft identity platform](https://www.youtube.com/watch?v=B416AxHoMJ4).
195+
194196
## Troubleshooting
195197

196198
### known issue on iOS 12

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/README-1-1-to-1-3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ In the **appsettings.json** file, replace the `TenantId` value with `"common"`
3939

4040
## Next steps
4141

42+
- A recording of a Microsoft Identity Platform developer session that covered this topic of developing a multi-tenant app with Azure Active Directory is available at [Develop multi-tenant applications with Microsoft identity platform](https://www.youtube.com/watch?v=B416AxHoMJ4).
43+
4244
- Learn how to enable users from [National clouds](../1-4-Sovereign) to sign-in to your application
4345
- Learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)

2-WebApp-graph-user/2-3-Multi-Tenant/README-National-Cloud.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ In addition to the public cloud​, Azure Active Directory is deployed in th
4444
- Microsoft Cloud Germany
4545
- Azure and Office 365 operated by 21Vianet in China
4646

47+
> A recording of a Microsoft Identity Platform developer session that covered this topic of developing a multi-tenant app with Azure Active Directory is available at [Develop multi-tenant applications with Microsoft identity platform](https://www.youtube.com/watch?v=B416AxHoMJ4).
48+
4749
### Overview
4850

4951
When it comes to developing apps, developers can choose to configure their app to be either single-tenant or multi-tenant during app registration in the [Azure portal](https://portal.azure.com).

2-WebApp-graph-user/2-3-Multi-Tenant/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ When it comes to developing apps, developers can choose to configure their app t
3737

3838
For more information about apps and tenancy, see [Tenancy in Azure Active Directory](https://docs.microsoft.com/azure/active-directory/develop/single-and-multi-tenant-apps)
3939

40+
> A recording of a Microsoft Identity Platform developer session that covered this topic of developing a multi-tenant app with Azure Active Directory is available at [Develop multi-tenant applications with Microsoft identity platform](https://www.youtube.com/watch?v=B416AxHoMJ4).
41+
4042
![Sign in with Azure AD](ReadmeFiles/topology.png)
4143

4244
## Scenario

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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
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

10+
#Requires -Modules AzureAD
11+
12+
813
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
914
Install-Module "AzureAD" -Scope CurrentUser
1015
}
@@ -13,10 +18,15 @@ $ErrorActionPreference = "Stop"
1318

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

2131
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
2232
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -25,17 +35,17 @@ This function removes the Azure AD applications for the sample. These applicatio
2535
# you'll need to sign-in with creds enabling your to create apps in the tenant)
2636
if (!$Credential -and $TenantId)
2737
{
28-
$creds = Connect-AzureAD -TenantId $tenantId
38+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
2939
}
3040
else
3141
{
3242
if (!$TenantId)
3343
{
34-
$creds = Connect-AzureAD -Credential $Credential
44+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3545
}
3646
else
3747
{
38-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
48+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3949
}
4050
}
4151

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
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

10+
#Requires -Modules AzureAD
11+
812
<#
913
This script creates the Azure AD applications needed for this sample and updates the configuration files
1014
for the visual Studio projects from the data in the Azure AD applications.
@@ -147,6 +151,11 @@ Function ConfigureApplications
147151
so that they are consistent with the Applications parameters
148152
#>
149153
$commonendpoint = "common"
154+
155+
if (!$azureEnvironmentName)
156+
{
157+
$azureEnvironmentName = "AzureCloud"
158+
}
150159

151160
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
152161
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -155,17 +164,17 @@ Function ConfigureApplications
155164
# you'll need to sign-in with creds enabling your to create apps in the tenant)
156165
if (!$Credential -and $TenantId)
157166
{
158-
$creds = Connect-AzureAD -TenantId $tenantId
167+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
159168
}
160169
else
161170
{
162171
if (!$TenantId)
163172
{
164-
$creds = Connect-AzureAD -Credential $Credential
173+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
165174
}
166175
else
167176
{
168-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
177+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
169178
}
170179
}
171180

@@ -174,6 +183,8 @@ Function ConfigureApplications
174183
$tenantId = $creds.Tenant.Id
175184
}
176185

186+
187+
177188
$tenant = Get-AzureADTenantDetail
178189
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
179190

@@ -191,7 +202,7 @@ Function ConfigureApplications
191202
$webAppAadApplication = New-AzureADApplication -DisplayName "WebApp-GroupClaims" `
192203
-HomePage "https://localhost:44321/" `
193204
-LogoutUrl "https://localhost:44321/signout-oidc" `
194-
-ReplyUrls "https://localhost:44321/", "https://localhost:44321/signin-oidc", "https://localhost:44321/Account/EndSession" `
205+
-ReplyUrls "https://localhost:44321/", "https://localhost:44321/signin-oidc" `
195206
-IdentifierUris "https://$tenantName/WebApp-GroupClaims" `
196207
-PasswordCredentials $key `
197208
-GroupMembershipClaims "SecurityGroup" `
@@ -223,7 +234,7 @@ Function ConfigureApplications
223234
# Add Required Resources Access (from 'webApp' to 'Microsoft Graph')
224235
Write-Host "Getting access from 'webApp' to 'Microsoft Graph'"
225236
$requiredPermissions = GetRequiredPermissions -applicationDisplayName "Microsoft Graph" `
226-
-requiredDelegatedPermissions "User.Read|Directory.Read.All" `
237+
-requiredDelegatedPermissions "Directory.Read.All" `
227238

228239
$requiredResourcesAccess.Add($requiredPermissions)
229240

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Sample": {
33
"Title": "Add authorization using groups & group claims to an ASP.NET Core Web app that signs-in users with the Microsoft identity platform",
4-
"Level": 400,
4+
"Level": 300,
55
"Client": "ASP.NET Core Web App",
66
"Service": "Microsoft Graph",
77
"RepositoryUrl": "microsoft-identity-platform-aspnetcore-webapp-tutorial",
@@ -18,14 +18,14 @@
1818
"Kind": "WebApp",
1919
"Audience": "AzureADMyOrg",
2020
"HomePage": "https://localhost:44321/",
21-
"ReplyUrls": "https://localhost:44321/, https://localhost:44321/signin-oidc, https://localhost:44321/Account/EndSession",
21+
"ReplyUrls": "https://localhost:44321/, https://localhost:44321/signin-oidc",
2222
"LogoutUrl": "https://localhost:44321/signout-oidc",
2323
"PasswordCredentials": "Auto",
2424
"GroupMembershipClaims": "SecurityGroup",
2525
"RequiredResourcesAccess": [
2626
{
2727
"Resource": "Microsoft Graph",
28-
"DelegatedPermissions": [ "User.Read", "Directory.Read.All" ]
28+
"DelegatedPermissions": [ "Directory.Read.All" ]
2929
}
3030
]
3131
}

5-WebApp-AuthZ/5-2-Groups/Controllers/UserProfileController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace WebApp_OpenIDConnect_DotNet.Controllers
1111
{
12-
// [Authorize(Roles = "8873daa2-17af-4e72-973e-930c94ef7549")] // Using groups ids in the Authorize attribute
12+
// This is how groups ids/names are used in the Authorize attribute
13+
//[Authorize(Roles = "8873daa2-17af-4e72-973e-930c94ef7549")]
1314
public class UserProfileController : Controller
1415
{
1516
private readonly ITokenAcquisition tokenAcquisition;
@@ -24,7 +25,7 @@ public UserProfileController(ITokenAcquisition tokenAcquisition, IMSGraphService
2425
[AuthorizeForScopes(Scopes = new[] { Constants.ScopeUserRead, Constants.ScopeDirectoryReadAll })]
2526
public async Task<IActionResult> Index()
2627
{
27-
// Using group ids/names in the IsInRole method
28+
// This is how group ids/names are used in the IsInRole method
2829
// var isinrole = User.IsInRole("8873daa2-17af-4e72-973e-930c94ef7549");
2930

3031
string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(new[] { Constants.ScopeUserRead, Constants.ScopeDirectoryReadAll });

0 commit comments

Comments
 (0)