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-3-AnyOrgOrPersonal/README.md
+43-24Lines changed: 43 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,19 @@ level: 100
6
6
service: ASP.NET Core Web App
7
7
endpoint: AAD v2.0
8
8
---
9
-
# Bulid an ASP.NET Core Web app signing-in users with the Microsoft identity platform
9
+
# An ASP.NET Core 2.x Web App which sign-in users with either work and school or Microsoft personal accounts
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.
This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users. Users can use personal accounts (including outlook.com, live.com, and others) as well as work and school accounts from any company or organization that has integrated with Azure Active Directory. It leverages the ASP.NET Core OpenID Connect middleware.
17
+
This sample shows how to build an ASP.NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users. Users can use either their personal accounts (including outlook.com, live.com, and others) as well as their work and school accounts. Thw work and school accounts are usually from an organization that has an Azure Active Directory tenant. It leverages the ASP.NET Core OpenID Connect middleware.
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 can learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
21
+
> This is the first chapter 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 can learn how to enable your [Web App to call a Web API on behalf of the signed-in user](../../2-WebApp-graph-user)
22
22
23
23
## How to run this sample
24
24
@@ -39,43 +39,62 @@ There is one project in this sample. To register it, you can:
39
39
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
40
40
```
41
41
42
-
3. Run the script to create your Azure AD application and configure the code of the sample application accordinly
42
+
3. Run the following script to create and configure your Azure AD application and configure the code of the sample application as well.
43
43
44
44
```PowerShell
45
45
.\AppCreationScripts\Configure.ps1
46
46
```
47
47
48
48
> Other ways of running the scripts are described in [App Creation Scripts](./AppCreationScripts/AppCreationScripts.md)
49
49
50
-
4. Once you've run the script, be sure to follow the manual steps. Indeed Azure AD PowerShell does not create an app which audience is Work or School + personal accounts, even if this registration is already possible from the Azure portal:
51
-
In the list of pages for the application registration of the application, select **Manifest**
52
-
- search for **signInAudience** and make sure it's set to **AzureADandPersonalMicrosoftAccount**
53
-
- Select **Save**
54
-
55
-
> Tip: If you register your apps with the scripts, to get directly to the app registration portal page for a give app, you can navigate to the links provided in the [AppCreationScripts\createdApps.html](AppCreationScripts\createdApps.html). This file is generated by the scripts during the app registration and configuration.
56
-
57
-
4. Open the Visual Studio solution and click start. That's it!
50
+
4. Once you've run the script, please ensure that you've followed the following manual steps. Azure AD PowerShell does not yet create an app whose audience is `Work or School + personal accounts`. This audience setting is only possible from the Azure portal as of today:
51
+
5. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account or a personal Microsoft account.
52
+
6. 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.
53
+
7. In the left-hand navigation blades, select the **Azure Active Directory** service, and then select **App registrations (Preview)**.
54
+
8. In the **App registrations (Preview)** blade, locate your newly created app in the list.
55
+
9. Select the **Manifest** blade for your app.
56
+
10. Search for **signInAudience** and make sure it's set to **AzureADandPersonalMicrosoftAccount**
> Tip: If you register your apps with the the provided Poweshell scripts, you can navigate directly to the app registration portal page of your newly created app, using links provided in the [AppCreationScripts\createdApps.html](AppCreationScripts\createdApps.html). This file is generated by the scripts during the app registration and configuration process.
66
+
67
+
12. Open the Visual Studio solution and click start. That's it!
58
68
59
69
- or, if you don't want to use automation, follow the steps below:
60
70
61
71
#### Choose the Azure AD tenant where you want to create your applications
62
72
73
+
As a first step you'll need to:
74
+
63
75
1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account or a personal Microsoft account.
64
-
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.
65
-
1. In the left-hand navigation pane, select the **Azure Active Directory** service, and then select **App registrations (Preview)**.
66
-
1. In **App registrations (Preview)** page, select **New registration**.
76
+
1. If your account is present in more than one Azure AD tenant, select your profile at the top right corner in the menu on top of the page, and then **switch directory**.
77
+
Change your portal session to the desired Azure AD tenant.
78
+
79
+
#### Register the webApp app (WebApp)
80
+
81
+
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
82
+
1. Select **New registration**.
67
83
1. When the **Register an application page** appears, enter your application's registration information:
68
84
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `WebApp`.
69
85
- In the **Supported account types** section, select **Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com)**.
70
-
- In the Redirect URI (optional) section, select **Web** in the combo-box.
71
-
- For the *Redirect URI*, enter the base URL for the sample. By default, this sample uses `https://localhost:44321/`.
72
-
- Select **Register** to create the application.
86
+
> Note that there are more than one redirect URIs. You'll need to add them from the **Authentication** tab later after the app has been created succesfully.
87
+
1. Select **Register** to create the application.
73
88
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project.
74
-
1. In the list of pages for the app, select **Authentication**.
75
-
- In the **Redirect URIs**, add a redirect URL of type Web and valued `https://localhost:44321/signin-oidc`
89
+
1. In the list of pages for the app, select **Authentication**..
90
+
- In the Redirect URIs section, select **Web** in the combo-box and enter the following redirect URIs.
91
+
-`https://localhost:44321/`
92
+
-`https://localhost:44321/signin-oidc`
76
93
- 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.
78
-
- Select **Save**.
94
+
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires
95
+
the [Implicit grant flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to
96
+
sign-in the user, and call an API.
97
+
1. Select **Save**.
79
98
80
99
> Note that unless the Web App calls a Web API no certificate or secret is needed.
81
100
@@ -111,7 +130,7 @@ In the **appsettings.json** file:
111
130
> Note: Replace *`Enter_the_Application_Id_here`* with the *Application Id* from the application Id you just registered in the Application Registration Portal.
112
131
113
132
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
133
+
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
134
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)
116
135
1. Open the **Startup.cs** file and:
117
136
@@ -188,7 +207,7 @@ You can also learn from the [1. WebApp signs-in users with Microsoft Identity (O
188
207
189
208
### known issue on iOS 12
190
209
191
-
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).
210
+
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).
192
211
193
212
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)
0 commit comments