You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-WebApp-OIDC/1-4-Sovereign/README.md
+43-52Lines changed: 43 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
services: active-directory
3
3
platforms: dotnet
4
-
author: jmprieur
4
+
author: negoe
5
5
level: 100
6
6
client: ASP.NET Core Web App
7
7
endpoint: AAD v2.0
@@ -10,57 +10,60 @@ endpoint: AAD v2.0
10
10
11
11
## Scenario
12
12
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 signin 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.
14
14
15
15

16
16
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.
17
18
19
+
In addition to the public cloud, Azure Active Directory is deployed in the following National clouds:
18
20
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:
20
26
21
27
- register your application in a specific portal, depending on the cloud
22
28
- use a specific authority, depending on the cloud in the config file for your application
23
29
- in case you want to call the graph, this requires a specific Graph endpoint URL, depending on the cloud.
24
30
25
31
More details in [Authentication in National Clouds](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud)
26
32
27
-
> This part of the tutorial is work in progress.
28
33
29
-
<!-- ## How to run this sample
30
34
31
-
To run this sample:
35
+
## How to run this sample
32
36
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:
34
38
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).
36
40
37
-
There is one project in this sample. To register it, you can:
38
41
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.
40
44
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:
43
46
44
-
```PowerShell
45
-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
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.
53
54
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
55
56
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.
57
60
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.
59
62
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.
61
66
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.
64
67
1. In the left-hand navigation pane, select the **Azure Active Directory** service, and then select **App registrations (Preview)**.
65
68
1. In **App registrations (Preview)** page, select **New registration**.
66
69
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:
74
77
1. In the list of pages for the app, select **Authentication**.
75
78
- In the **Redirect URIs**, add a redirect URL of type Web and valued `https://localhost:44321/signin-oidc`
76
79
- 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 signin the user.
78
81
- Select **Save**.
79
82
80
83
> Note that unless the Web App calls a Web API no certificate or secret is needed.
81
84
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:
> 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
97
86
98
-
In the **appsettings.json** file:
87
+
#### Option 1: In the **appsettings.json** file:
99
88
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*.
102
93
103
-
#### Option 2: Create the sample from the command line
94
+
#### Option 2: Create and configure sample from the command line
104
95
105
96
1. Run the following command to create a sample from the command line using the `SingleOrg` template:
106
97
@@ -111,7 +102,7 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
111
102
> 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.
112
103
113
104
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
115
106
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)
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.
138
129
139
130
1. Change the `Properties\launchSettings.json` file to ensure that you start your web app from <https://localhost:44321> as registered. For this:
140
131
- update the `sslPort` of the `iisSettings` section to be `44321`
@@ -146,13 +137,13 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
146
137
147
138
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.
148
139
149
-
## Toubleshooting
140
+
## Troubleshooting
150
141
151
142
### known issue on iOS 12
152
143
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).
154
145
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)
156
147
157
148
## About The code
158
149
@@ -162,7 +153,7 @@ This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign
162
153
- 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`.
163
154
- Integrating with the session cookie ASP.NET Core middleware to establish a session for the user.
164
155
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):
166
157
167
158
168
159
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
171
162
172
163
## Next steps
173
164
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 signin
175
166
- Learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
Copy file name to clipboardExpand all lines: 1-WebApp-OIDC/1-4-Sovereign/appsettings.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"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]",
4
4
"Domain": "[Enter the domain of your tenant, e.g. contoso.onmicrosoft.com]",
5
5
"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]",
6
6
"ClientId": "[Enter the Client Id (Application ID obtained from the Azure portal), e.g. ba74781c2-53c2-442a-97c2-3d60re42f403]",
0 commit comments