Skip to content

Commit 8038169

Browse files
negoejmprieur
authored andcommitted
Sovereign Tutorial Update (#81)
* Sovereign Tutorial * Comments Fixed * appsetiings.jason updates * MS Graph folder for Sovereign scenarios
1 parent dab4a6f commit 8038169

File tree

76 files changed

+25272
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+25272
-53
lines changed

1-WebApp-OIDC/1-4-Sovereign/README.md

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
services: active-directory
33
platforms: dotnet
4-
author: jmprieur
4+
author: negoe
55
level: 100
66
client: ASP.NET Core Web App
77
endpoint: AAD v2.0
@@ -10,57 +10,60 @@ endpoint: AAD v2.0
1010

1111
## Scenario
1212

13-
This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users. Users can only sign-in with their `work and school` accounts in their organization **belonging to national or sovereign clouds**. It leverages the ASP.NET Core OpenID Connect middleware.
13+
This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users. Users can only sign in with their `work and school` accounts in their organization **belonging to national or sovereign clouds**. This sample use US Government cloud scenario. It leverages the ASP.NET Core OpenID Connect middleware.
1414

1515
![Sign in with Azure AD](ReadmeFiles/sign-in.png)
1616

17+
National clouds (aka Sovereign clouds) are physically isolated instances of Azure. These regions of Azure are designed to make sure that data residency, sovereignty, and compliance requirements are honored within geographical boundaries.
1718

19+
In addition to the public cloud​, Azure Active Directory is deployed in the following National clouds:  
1820

19-
Note that, enabling your application for sovereign clouds requires you to:
21+
- Azure US Government
22+
- Azure China 21Vianet
23+
- Azure Germany
24+
25+
Note that enabling your application for sovereign clouds requires you to:
2026

2127
- register your application in a specific portal, depending on the cloud
2228
- use a specific authority, depending on the cloud in the config file for your application
2329
- in case you want to call the graph, this requires a specific Graph endpoint URL, depending on the cloud.
2430

2531
More details in [Authentication in National Clouds](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud)
2632

27-
> This part of the tutorial is work in progress.
2833

29-
<!-- ## How to run this sample
3034

31-
To run this sample:
35+
## How to run this sample
3236

33-
> Pre-requisites: Install .NET Core 2.2 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://www.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
37+
To run this sample:
3438

35-
### Step 1: Register the sample with your Azure AD tenant
39+
> Pre-requisites: Install .NET Core 2.2 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://ww w.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
3640
37-
There is one project in this sample. To register it, you can:
3841

39-
- either use PowerShell scripts that **automatically** creates the Azure AD applications and related objects (passwords, permissions, dependencies) for you and modify the Visual Studio projects' configuration files. If you want to use this automation:
42+
### Step 1: Download/Clone this sample code
43+
This sample was created from the dotnet core 2.2 [dotnet new mvc](https://docs.microsoft.com/dotnet/core/tools/dotnet-new?tabs=netcore2x) template with `SingleOrg` authentication, and then tweaked to let it support tokens for the Azure AD V2 endpoint.
4044

41-
1. On Windows run PowerShell and navigate to the solution's folder
42-
2. In PowerShell run:
45+
You can clone this sample from your shell or command line:
4346

44-
```PowerShell
45-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
47+
```console
48+
git clone https://github.com/Azure-Samples/microsoft-identity-platform-aspnetcore-webapp-tutorial webapp
49+
cd webapp
50+
cd "1-WebApp-OIDC/1-4-Sovereign"
4651
```
4752

48-
3. Run the script to create your Azure AD application and configure the code of the sample application accordinly
49-
50-
```PowerShell
51-
.\AppCreationScripts\Configure.ps1
52-
```
53+
> Given that the name of the sample is very long, and so are the name of the referenced NuGet packages, you might want to clone it in a folder close to the root of your hard drive, to avoid file size limitations on Windows.
5354
54-
> Other ways of running the scripts are described in [App Creation Scripts](./AppCreationScripts/AppCreationScripts.md)
55+
### Step 2: Register the sample with your Azure AD tenant
5556

56-
4. Open the Visual Studio solution and click start. That's it!
57+
1. Sign in to the [US Government Azure portal](https://portal.azure.us)
58+
59+
- For registering your app in other National Clouds go to [App Registration endpoints](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud#app-registration-endpoints) of the National Cloud of your choice using either a work or school account.
5760

58-
- or, if you don't want to use automation, follow the steps below:
61+
> Note: Azure Germany doesn't support **App registrations (Preview)* experience.
5962
60-
#### Choose the Azure AD tenant where you want to create your applications
63+
2. Choose the Azure AD tenant where you want to create your applications
64+
- If your account is present in more than one Azure AD tenant, select profile button at the top-right corner in the menu on top of the page and select `Switch Directory`.
65+
- On `Directory + Subscription` switch your portal session to the desired Azure AD tenant.
6166

62-
1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account or a personal Microsoft account.
63-
1. If your account is present in more than one Azure AD tenant, select `Directory + Subscription` at the top right corner in the menu on top of the page, and switch your portal session to the desired Azure AD tenant.
6467
1. In the left-hand navigation pane, select the **Azure Active Directory** service, and then select **App registrations (Preview)**.
6568
1. In **App registrations (Preview)** page, select **New registration**.
6669
1. When the **Register an application page** appears, enter your application's registration information:
@@ -74,33 +77,21 @@ There is one project in this sample. To register it, you can:
7477
1. In the list of pages for the app, select **Authentication**.
7578
- In the **Redirect URIs**, add a redirect URL of type Web and valued `https://localhost:44321/signin-oidc`
7679
- In the **Advanced settings** section set **Logout URL** to `https://localhost:44321/signout-oidc`
77-
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to sign-in the user.
80+
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to sign in the user.
7881
- Select **Save**.
7982

8083
> Note that unless the Web App calls a Web API no certificate or secret is needed.
8184
82-
### Step 2: Download/ Clone this sample code or build the application using a template
83-
84-
This sample was created from the dotnet core 2.2 [dotnet new mvc](https://docs.microsoft.com/dotnet/core/tools/dotnet-new?tabs=netcore2x) template with `SingleOrg` authentication, and then tweaked to let it support tokens for the Azure AD V2 endpoint. You can clone/download this repository or create the sample from the command line:
85-
86-
#### Option 1: Download/ clone this sample
87-
88-
You can clone this sample from your shell or command line:
89-
90-
```console
91-
git clone https://github.com/Azure-Samples/microsoft-identity-platform-aspnetcore-webapp-tutorial webapp
92-
cd webapp
93-
cd "1-WebApp-OIDC\1-1-MyOrg"
94-
```
95-
96-
> Given that the name of the sample is very long, and so are the name of the referenced NuGet packages, you might want to clone it in a folder close to the root of your hard drive, to avoid file size limitations on Windows.
85+
### Step 3: Configure your App
9786

98-
In the **appsettings.json** file:
87+
#### Option 1: In the **appsettings.json** file:
9988

100-
- replace the `ClientID` value with the *Application ID* from the application you registered in Application Registration portal on *Step 1*.
101-
- replace the `TenantId` value with he *Tenant ID* where you registered your Application on *Step 1*.
89+
- replace the `Instance` value with the relevant authority value of the US Government cloud that is `https://login.microsoftonline.us`
90+
- For other National Clouds go to [List of authority of National Clouds](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud#azure-ad-authentication-endpoints)
91+
- replace the `ClientID` value with the *Application ID* from the application you registered in Application Registration portal on *Step 2*.
92+
- replace the `TenantId` value with the *Tenant ID* where you registered your Application on *Step 2*.
10293

103-
#### Option 2: Create the sample from the command line
94+
#### Option 2: Create and configure sample from the command line
10495

10596
1. Run the following command to create a sample from the command line using the `SingleOrg` template:
10697

@@ -111,7 +102,7 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
111102
> Note: Replace *`Enter_the_Application_Id_here`* with the *Application Id* from the application Id you just registered in the Application Registration Portal and *`<yourTenantId>`* with the *Directory (tenant) ID* where you created your application.
112103

113104
1. Open the generated project (.csproj) in Visual Studio, and save the solution.
114-
1. Add the `Microsoft.Identity.Web.csproj` project which is located at the root of this sample repo, to your solution (**Add Existing Project ...**). It's used to simplify signing-in and, in the next tutorial phases, to get a token
105+
1. Add the `Microsoft.Identity.Web.csproj` project, which is located at the root of this sample repo, to your solution (**Add Existing Project ...**). It's used to simplify signing-in and, in the next tutorial phases, to get a token
115106
1. Add a reference from your newly generated project to `Microsoft.Identity.Web` (right click on the **Dependencies** node under your new project, and choose **Add Reference ...**, and then in the projects tab find the `Microsoft.Identity.Web` project)
116107
1. Open the **Startup.cs** file and:
117108
@@ -134,7 +125,7 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
134125
services.AddAzureAdV2Authentication(Configuration);
135126
```
136127
137-
This enables your application to use the Microsoft identity platform (fomerly Azure AD v2.0) endpoint. This endpoint is capable of signing-in users both with their Work and School and Microsoft Personal accounts.
128+
This enables your application to use the Microsoft identity platform (formerly known as Azure AD v2.0) endpoint. This endpoint is capable of signing-in users both with their Work and School and Microsoft Personal accounts.
138129
139130
1. Change the `Properties\launchSettings.json` file to ensure that you start your web app from <https://localhost:44321> as registered. For this:
140131
- update the `sslPort` of the `iisSettings` section to be `44321`
@@ -146,13 +137,13 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
146137
147138
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 Azure AD v2 endpoint. Sign in with your personal account or with work or school account.
148139
149-
## Toubleshooting
140+
## Troubleshooting
150141
151142
### known issue on iOS 12
152143
153-
ASP.NET core applications create session cookies that represent the identity of the caller. Some Safari users using iOS 12 had issues which are described in [ASP.NET Core #4467](https://github.com/aspnet/AspNetCore/issues/4647) and the Web kit bugs database [Bug 188165 - iOS 12 Safari breaks ASP.NET Core 2.1 OIDC authentication](https://bugs.webkit.org/show_bug.cgi?id=188165).
144+
ASP.NET core applications create session cookies that represent the identity of the caller. Some Safari users using iOS 12 had issues, which are described in [ASP.NET Core #4467](https://github.com/aspnet/AspNetCore/issues/4647) and the Web kit bugs database [Bug 188165 - iOS 12 Safari breaks ASP.NET Core 2.1 OIDC authentication](https://bugs.webkit.org/show_bug.cgi?id=188165).
154145
155-
If your web site needs to be accessed from users using iOS 12, you probably want to disable the SameSite protection, but also ensure that state changes are protected with CSRF anti-forgery mecanism. See the how to fix section of [Microsoft Security Advisory: iOS12 breaks social, WSFed and OIDC logins #4647](https://github.com/aspnet/AspNetCore/issues/4647)
146+
If your web site needs to be accessed from users using iOS 12, you probably want to disable the SameSite protection, but also ensure that state changes are protected with CSRF anti-forgery mechanism. See the how to fix section of [Microsoft Security Advisory: iOS12 breaks social, WSFed, and OIDC logins #4647](https://github.com/aspnet/AspNetCore/issues/4647)
156147
157148
## About The code
158149
@@ -162,7 +153,7 @@ This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign
162153
- Processing OpenID Connect sign-in responses by validating the signature and issuer in an incoming JWT, extracting the user's claims, and putting the claims in `ClaimsPrincipal.Current`.
163154
- Integrating with the session cookie ASP.NET Core middleware to establish a session for the user.
164155

165-
You can trigger the middleware to send an OpenID Connect sign-in request by decorating a class or method with the `[Authorize]` attribute or by issuing a challenge (see the [AccountController.cs](https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Areas/AzureAD/Controllers/AccountController.cs) file which is part of ASP.NET Core):
156+
You can trigger the middleware to send an OpenID Connect sign-in request by decorating a class or method with the `[Authorize]` attribute or by issuing a challenge (see the [AccountController.cs](https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Areas/AzureAD/Controllers/AccountController.cs) file, which is part of ASP.NET Core):
166157

167158

168159
The middleware in this project is created as a part of the open-source [ASP.NET Core Security](https://github.com/aspnet/aspnetcore) project.
@@ -171,7 +162,7 @@ These steps are encapsulated in the [Microsoft.Identity.Web](..\..\Microsoft.Ide
171162

172163
## Next steps
173164

174-
- Learn how to enable [any organization](../1-2-AnyOrg) or [any Microsoft accounts](../1-3-AnyOrgOrPersonal) to sign-in
165+
- Learn how to enable [any organization](../1-2-AnyOrg) or [any Microsoft accounts](../1-3-AnyOrgOrPersonal) to sign in
175166
- Learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
176167

177168
## Learn more

1-WebApp-OIDC/1-4-Sovereign/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AzureAd": {
3-
"Instance": "https://login.microsoftonline.com/",
3+
"Instance": "[Enter the right Azure AD authentication endpoints, e.g. for US Government https://login.microsoftonline.us]",
44
"Domain": "[Enter the domain of your tenant, e.g. contoso.onmicrosoft.com]",
55
"TenantId": "[Enter 'common', or 'organizations' or the Tenant Id (Obtained from the Azure portal. Select 'Endpoints' from the 'App registrations' blade and use the GUID in any of the URLs), e.g. da41245a5-11b3-996c-00a8-4d99re19f292]",
66
"ClientId": "[Enter the Client Id (Application ID obtained from the Azure portal), e.g. ba74781c2-53c2-442a-97c2-3d60re42f403]",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
./vs
2+
./obj
3+
./bin

0 commit comments

Comments
 (0)