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
> The sample in this folder is part of a multi-phase tutorial. This folder is about the second phase named **Web API now calls Microsoft Graph**.
15
15
> The first phase is available from [1. Desktop app calls Web API](../1.%20Desktop%20app%20calls%20Web%20API).
16
16
>
17
17
> This article [README-incremental-instructions.md](README-incremental-instructions.md) builds on top of the README.md of the first part. If you want to see the full instructions on how to configure the sample, see [README.md](README.md)
18
18
19
-
> At that time, the Azure AD v2.0 endpoint does not yet completely support the on-behalf-of flow for users signing-in with a Microsoft Personal account. Limitations are called out in the [Current limitations](#Current-limitations) section
20
19
21
20
## About this sample
22
21
@@ -29,7 +28,7 @@ endpoint: AAD v2.0
29
28
-[How to run this sample](#How-to-run-this-sample)
30
29
-[Step 1: Clone or download this repository](#step-1--clone-or-download-this-repository)
31
30
-[Step 2: Register the sample with your Azure Active Directory tenant](#step-2--register-the-sample-with-your-azure-active-directory-tenant)
32
-
-[Step 3: Configure the sample to use your Azure AD tenant](#step-3--configure-the-sample-to-use-your-azure-ad-tenant)
31
+
-[Step 3: Configure the sample code to use your Azure AD tenant](#step-3--configure-the-sample-code-to-use-your-azure-ad-tenant)
33
32
-[Step 4: Run the sample](#step-4-run-the-sample)
34
33
-[Troubleshooting](#Troubleshooting)
35
34
-[Current limitations](#Current-limitations)
@@ -76,6 +75,8 @@ There are two projects in this sample. Each needs to be separately registered in
76
75
-**automatically** creates the Azure AD applications and related objects (passwords, permissions, dependencies) for you
77
76
- modify the Visual Studio projects' configuration files.
78
77
78
+
> Note however that the automation will not, at this point, allow you to sign-in with a personal Microsoft account. If you want to allow sign in with personal Microsoft accounts, use the manual instructions.
79
+
79
80
#### Using scripts
80
81
81
82
If you want to use this automation:
@@ -95,14 +96,13 @@ If you want to use this automation:
95
96
- in the manifest, search for **"accessTokenAcceptedVersion"**, and replace **null** by **2**. This property lets Azure AD know that the Web API accepts v2.0 tokens
96
97
- search for **signInAudience** and make sure it's set to **AzureADandPersonalMicrosoftAccount**
97
98
- Select **Save**
98
-
1. In the **Authentication** page for the *TodoListService-v2* application, check the `urn:ietf:wg:oauth:2.0:oob` reply URI so that the client can propose incremental consent to the user for the Web API when needed.
99
-
1. In tthe application registration page for the *TodoListClient-v2* application, select the **Manifest** section:
99
+
1. In the application registration page for the *TodoListClient-v2* application, select the **Manifest** section:
100
100
- search for **signInAudience** and make sure it's set to **AzureADandPersonalMicrosoftAccount**
101
101
- Select **Save**
102
102
103
103
> Tip: 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.
104
104
105
-
1. Open the Visual Studio solution and click start
105
+
5. Open the Visual Studio solution and click start
106
106
107
107
If you don't want to use this automation, follow the steps below
108
108
@@ -112,7 +112,7 @@ These instructions only show the differences with the first part.
112
112
113
113
#### Register the service app (TodoListService)
114
114
115
-
1. In **App registrations (Preview)** page, find the *TodoListService-2* app
115
+
1. In **App registrations** page, find the *TodoListService-2* app
116
116
1. From the **Certificates & secrets** page, in the **Client secrets** section, choose **New client secret**:
117
117
- Type a key description (of instance `app secret`),
118
118
- Select a key duration of either **In 1 year**, **In 2 years**, or **Never Expires**.
@@ -123,32 +123,34 @@ These instructions only show the differences with the first part.
123
123
- Click the **Add a permission** button and then,
124
124
- Ensure that the **Microsoft APIs** tab is selected
125
125
- In the *Commonly used Microsoft APIs* section, click on **Microsoft Graph**
126
-
- In the **Delegated permissions** section, ensure that the right permissions are checked: **User.Read**. Use the search box if necessary.
126
+
- In the **Delegated permissions** section, ensure that the right permissions are checked: **User.Read** and **offline_access**. Use the search box if necessary.
127
127
- Select the **Add permissions** button
128
-
-[Optional] if you are a tenant admin, and agree to grant the admin consent to the web api, select **Grant admin consent for {your tenant domain}**.
129
-
1.[Otherwise] If you have not granted admin consent to the Web API in the previous optional step, select **Authentication** in the list of pages and there:
130
-
- Check the `urn:ietf:wg:oauth:2.0:oob` Redirect URI checkbox. This is so that the client can propose incremental consent to the user for the downstream web apis used by our *TodoListService-v2* Web API.
131
-
- Select **Save**
128
+
-[Optional] if you are a tenant admin, and agree to grant the admin consent to the web api, select **Grant admin consent for {your tenant domain}**. If you don't do
129
+
it, users will be presented a consent screen enabling them to consent to using the web api. The consent screen will also mention the permissions required by the web api itself.
132
130
1.[Optional] Select the **Manifest** section and:
133
131
- in the manifest, search for **"accessTokenAcceptedVersion"**, and see that its value is **2**. This property lets Azure AD know that the Web API accepts v2.0 tokens
134
132
- Select **Save**
135
133
136
-
> Important: it's up to the Web API to decide which version of token (v1.0 or v2.0) it accepts. Then when clients request a token for your Web API using the v2.0 endpoint, they'll get a token which version is accepted by the Web API. The code validating the tokens in this sample was written to accept both versions.
134
+
> Important: it's up to the Web API to decide which version of token (v1.0 or v2.0) it accepts. Then when clients request a token for your Web API using the Microsoft identity platform endpoint, they'll get a token which version is accepted by the Web API. The code validating the tokens in this sample was written to accept both versions.
137
135
138
136
#### Register the client app (TodoListClient)
139
137
140
138
Nothing more to do more here. All was done in the first part
141
139
142
140
### Step 3: Configure the sample to use your Azure AD tenant
143
141
144
-
By default the sample is configured to enable users to sign in with any work and school accounts (AAD) accounts.
145
-
This constrain is ensured by `ida:Tenant` in `TodoListClient\App.Config` having the value `organizations`.
142
+
By default the sample is configured to enable users to sign in with any work and school accounts (AAD) or personal Microsoft accounts.
143
+
This constraint is ensured by `ida:Tenant` in `TodoListClient\App.Config` having the value `common`.
146
144
147
145
#### Configure the TodoListService C# project
148
146
149
147
1. Open the solution in Visual Studio.
150
148
1. In the *TodoListService-v2* project, open the `appsettings.json` file.
151
149
1. Find the `ClientSecret` property and replace the existing value with the key you saved during the creation of the `TodoListService-v2` app, in the Azure portal.
150
+
> Note
151
+
> In chapter 1, the protected Web API did not call any downstrream API. In this chapter it does, and thus
152
+
> it needs to acquire s token, and becomes a confidential client. Therefore it needs to prove its identity to
153
+
> Azure AD through a client secret (or a certificate)
152
154
153
155
#### Configure the TodoListClient C# project
154
156
@@ -158,12 +160,9 @@ Nothing more to do more here. All was done in the first part
158
160
159
161
Clean the solution, rebuild the solution, and run it
160
162
161
-
### Current limitations
163
+
### Alternative architecture
162
164
163
-
The on-behalf-of flow works for Microsoft Personal accounts, but the consent is not yet rolled-up in the client for the user to consent to the Web API calling the downstream API (here Microsoft Graph). To make this work, the suggestion is:
164
-
165
-
- either to use the same client ID in the Client and the Service. This way the consent for the service will appear in the client.
166
-
- or to provide a protected page on the Web API (which therefore also becomes a Web app) so that the user can have an interaction
165
+
This part of the sample uses different client ID for the client and the service and uses the on-behalf-of flow. If you are the author of both the client and the service, you might alternatively want to use the same client ID in the Client and the Service. This approach is described in the third part of the tutorial [3.-Web-api-call-Microsoft-graph-for-personal-accounts](../3.-Web-api-call-Microsoft-graph-for-personal-accounts)
- At the beginning of the `Configure` method, insert `app.UseSession()`. This code ensures that the session exists for the session-based token cache to work properly.
Thecodefor this method is available in [Microsoft.Identity.Web\Client\TokenAcquisition.cs L457-L493](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/blob/4f9a9bc7f08e79f1a3e908cb513c59f1976470da/Microsoft.Identity.Web/TokenAcquisition.cs#L457-L493)
336
324
337
325
#### On the client side
338
326
339
327
On the clientside, whenitcallstheWebAPIandreceivesa 403 withawww-Authenticateheader, theclientwillcallthe `HandleChallengeFromWebApi` method, whichwill
-tolearnmoreaboutthescenario, see [Scenario: WebappthatcallswebAPIs](https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-overview)
360
+
361
+
-tolearnmoreaboutMicrosoft.Identity.Web, see [Microsoft.Identity.Web/README.md](../Microsoft.Identity.Web/README.md)
-Tolearnmoreaboutthecode, visit [ConceptualdocumentationforMSAL.NET](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki#conceptual-documentation) and in particular:
0 commit comments