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-1-MyOrg/README.md
+26-22Lines changed: 26 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ level: 100
6
6
client: ASP.NET Core Web App
7
7
endpoint: AAD v2.0
8
8
---
9
-
# Build an ASP.NET Core Web app signing-in users with the Microsoft identity platform
9
+
# An ASP.NET Core Web app signing-in users with the Microsoft identity platform in your organization
10
10
11
11
> This sample is for Azure AD, not Azure AD B2C. See [active-directory-b2c-dotnetcore-webapp](https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp), until we incorporate the B2C variation in the tutorial.
12
12
@@ -18,7 +18,8 @@ This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Conn
18
18
19
19

20
20
21
-
> This is the first phase of a set of tutorials. Once you understand how to sign-in users in an ASP.NET Core Web App with Open Id Connect, can learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user) in a later chapter
21
+
> This is the first chapter of this ASP.NET Core Web App tutorial. Once you understand how to sign-in users in an ASP.NET Core Web App with Open Id Connect, can learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user) in a later chapter.
22
+
You can also sign-in users in any or several Azure Active Directory organizations, and even with Microsoft personal accounts or social identities. For more details the parent directory's [Readme.md](../Readme.md)
22
23
23
24
## How to run this sample
24
25
@@ -35,15 +36,15 @@ There is one project in this sample. To register it, you can:
35
36
1. On Windows run PowerShell and navigate to the solution's folder
36
37
2. In PowerShell run:
37
38
38
-
```PowerShell
39
-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
40
-
```
39
+
```PowerShell
40
+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
41
+
```
41
42
42
43
3. Run the script to create your Azure AD application and configure the code of the sample application accordinly
43
44
44
-
```PowerShell
45
-
.\AppCreationScripts\Configure.ps1
46
-
```
45
+
```PowerShell
46
+
.\AppCreationScripts\Configure.ps1
47
+
```
47
48
48
49
> Other ways of running the scripts are described in [App Creation Scripts](./AppCreationScripts/AppCreationScripts.md)
49
50
@@ -75,8 +76,8 @@ As a first step you'll need to:
75
76
- `https://localhost:44321/signin-oidc`
76
77
- In the **Advanced settings** section set **Logout URL** to `https://localhost:44321/signout-oidc`
77
78
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires
78
-
the [Implicit grant flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to
79
-
sign-in the user, and call an API.
79
+
the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to
80
+
sign-in the user.
80
81
1. Select **Save**.
81
82
82
83
> Note that unless the Web App calls a Web API, no certificate or secret is needed.
@@ -120,24 +121,24 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
120
121
121
122
- at the top of the file, add the following using directive:
122
123
123
-
```CSharp
124
-
using Microsoft.Identity.Web;
125
-
```
124
+
```CSharp
125
+
using Microsoft.Identity.Web;
126
+
```
126
127
127
128
- in the `ConfigureServices` method, replace the two following lines:
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.
141
+
This enables your application to use the Microsoft identity platform (formerly Azure AD v2.0) endpoint. This endpoint is capable of signing-in users both with their Work and School and Microsoft Personal accounts.
141
142
142
143
1. Change the `Properties\launchSettings.json` file to ensure that you start your web app from <https://localhost:44321> as registered. For this:
143
144
- update the `sslPort` of the `iisSettings` section to be `44321`
@@ -149,7 +150,6 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
149
150
150
151
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.
151
152
152
-
> Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
153
153
154
154
## Toubleshooting
155
155
@@ -159,6 +159,8 @@ ASP.NET core applications create session cookies that represent the identity of
159
159
160
160
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)
161
161
162
+
> Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
163
+
162
164
## About The code
163
165
164
166
This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign in users from a single Azure AD tenant. The middleware is initialized in the `Startup.cs` file by passing it the Client ID of the app, and the URL of the Azure AD tenant where the app is registered. These values are read from the `appsettings.json` file. The middleware takes care of:
@@ -169,18 +171,20 @@ This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign
169
171
170
172
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):
171
173
172
-
173
174
The middleware in this project is created as a part of the open-source [ASP.NET Core Security](https://github.com/aspnet/aspnetcore) project.
174
175
175
176
These steps are encapsulated in the [Microsoft.Identity.Web](..\..\Microsoft.Identity.Web) project, and in particular in the [StartupHelper.cs](..\..\Microsoft.Identity.Web\StartupHelper.cs) file
176
177
177
178
## Next steps
178
-
179
-
- Learn how to enable [any organization](../1-2-AnyOrg) or [any Microsoft accounts](../1-3-AnyOrgOrPersonal) to sign-in
180
-
- Learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
179
+
Learn how to:
180
+
- Change your app to sign-in users from [any organization](../1-2-AnyOrg/README-1-1-to-1-2.md) or [any Microsoft accounts](../1-3-AnyOrgOrPersonal/README-1-1-to-1-3.md)
181
+
- Enable users from [National clouds](../1-4-Sovereign) to sign-in to your application
182
+
- enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
- [Quickstart: Register an application with the Microsoft identity platform (Preview)](https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app)
# Change your ASP.NET Core Web app to sign-in users in any org with the Microsoft identity platform
10
+
11
+
> This sample is for Azure AD, not Azure AD B2C. See [active-directory-b2c-dotnetcore-webapp](https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp), until we incorporate the B2C variation in the tutorial.
> This is the second chapter of the first phase of this ASP.NET Core Web App tutorial. You learnt previously how to build an ASP.NET Core Web app signing-in users with the Microsoft identity platform in [your organization](../1-1-MyOrg). This chapter describes how to change that application to enable users to sign-in from any organization.
20
+
>
21
+
> If you are not interested in the differentials, but want to understand all the steps, read the full [Readme.md](./Readme.md)
22
+
23
+
## Enable users from any organization to sign-in to your Web app
24
+
25
+
### Changes to the application registration
26
+
27
+
Your application was registered to sign-in users in [your organization](../1-1-MyOrg) only. To enable users signing-in from any organization, you need to change the app registration in the Azure portal
28
+
29
+
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
30
+
1. Find your application in the list and select it.
31
+
1. In the **Authentication** section for your application, in the **Supported account types** section, select **Accounts in any organizational directory**.
32
+
1. Select **Save**
33
+
34
+
### Changes to the code
35
+
36
+
You will also need to change the configuration file in the code:
37
+
38
+
In the **appsettings.json** file, replace the `TenantId` value with `"organizations"`
39
+
40
+
### Remark: effective sign-in audience
41
+
42
+
The actual sign-in audience (accounts to sign-in) is the lowest set of what is specified in both the application registration portal and the `appsetttings.json` config file. In other words, you could also achieve the same result by:
43
+
44
+
- setting in the portal the **Supported account types** to **Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com)** and set the `TenantId` value to `"organizations"` in the **appsettings.json** file
45
+
- setting in the portal the **Supported account types** to **Accounts in any organizational directory** and set the `TenantId` value to `"common"` in the **appsettings.json** file
46
+
47
+
## How to restrict users from specific organizations to sign-in to your web app
48
+
49
+
In order to restrict users from specific organizations to sign-in to your web app, you'll need to follow the steps above, and customize a bit more the code to restrict the valid token issuers. The token issuers are really the tenanted Azure AD authority which are allowed to issue a token to access your web application.
50
+
51
+
In the `Startup.cs` file, in the `ConfigureServices` method, after `services.AddAzureAdV2Authentication(Configuration)` add some code to validate specific issuers by overriding the `TokenValidationParameters.IssuerValidator` delegate.
0 commit comments