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
@@ -34,7 +34,7 @@ In the fourth chapter, we would enhance our protected Web API using Azure AD [Pr
34
34
35
35
### Overview
36
36
37
-
In This sample, the Web API is called by a .NET Desktop WPF application.
37
+
In This sample, the Web API is called by a .NET console application.
38
38
39
39
The .Net application uses the Microsoft Authentication Library [MSAL.NET](https://aka.ms/msal-net) to obtain a JWT [Access Token](https://docs.microsoft.com/azure/active-directory/develop/access-tokens) through the [OAuth 2.0](https://docs.microsoft.com/azure/active-directory/develop/active-directory-protocols-oauth-code) protocol. The access token is sent to the ASP.NET Core Web API, which authorizes the user using the ASP.NET JWT Bearer Authentication middleware.
40
40
@@ -44,13 +44,12 @@ The .Net application uses the Microsoft Authentication Library [MSAL.NET](https:
44
44
45
45
The Web API (TodoListService) maintains an in-memory collection of to-do items for each authenticated user. Several applications signed-in under the same identity will share the same to-do list.
46
46
47
-
The WPF application (TodoListClient) allows a user to:
47
+
The desktop application (TodoListClient) allows a user to:
48
48
49
-
- Sign-in. The first time a user signs in, a consent screen is presented where the user consents for the application accessing the TodoList Service on their behalf.
50
-
- When the user has signed-in, the user is presented with a list of to-do items fetched from the Web API for this signed-in identity.
51
-
- The user can add more to-do items by clicking on *Add item* button.
49
+
- Enter an item. When the user enters the first item, sign-in screen is displayed. The first time a user signs in, a consent screen is presented where the user consents for the application accessing the TodoList Service on their behalf.
50
+
- Each time, the user enters an item, a list of to-do items are fetched from the Web API for this signed-in identity.
52
51
53
-
Next time a user runs the application, the user is signed-in with the same identity as the WPF application maintains a cache on disk. Users can clear the cache (which will have the effect of them signing out).
52
+
Next time a user runs the application, the user is signed-in with the same identity as the console application maintains a cache on disk. Users can clear the cache (which will have the effect of them signing out).
@@ -90,15 +89,15 @@ When you start the Web API from Visual Studio, depending on the browser you use,
90
89
- an empty web page (with Microsoft Edge)
91
90
- or an error HTTP 401 (with Chrome)
92
91
93
-
This behavior is expected as the browser is not authenticated. The WPF application will be authenticated, so it will be able to access the Web API.
92
+
This behavior is expected as the browser is not authenticated. The console application will be authenticated, so it will be able to access the Web API.
94
93
95
94
Explore the sample by signing in into the TodoList client, adding items to the To Do list, removing the user account (clearing the cache), and starting again. As explained, if you stop the application without removing the user account, the next time you run the application, you won't be prompted to sign in again. That is because the sample implements a persistent cache for MSAL, and remembers the tokens from the previous run.
96
95
97
96
NOTE: Remember, the To-Do list is stored in memory in this `TodoListService-v2` sample. Each time you run the TodoListService API, your To-Do list will get emptied.
98
97
99
98
## How was the code created
100
99
101
-
### Code for the WPF app
100
+
### Code for the console app
102
101
103
102
The focus of this tutorial is PoP (Proof of Possession).
104
103
@@ -116,52 +115,41 @@ In `MainWindow.xaml.cs`, You'll need to:
116
115
.Build();
117
116
```
118
117
119
-
- Create an `HttpRequestMessage` by passing the verb (for instance `HttpMethod.Get`) and the URL of the Web API to call.
118
+
- Create an `HttpRequestMessage` by passing the verb (for instance `HttpMethod.Post`) and the URL of the Web API to call.
Copy file name to clipboardExpand all lines: 4.-Console-app-calls-web-API-with-PoP/README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -222,7 +222,9 @@ NOTE: Remember, the To-Do list is stored in memory in this `TodoListService-v2`
222
222
223
223
The focus of this tutorial is PoP (Proof of Possession).
224
224
225
-
With PoP, the programming model is a bit different from the way MSAL.NET usually works. A PoP token contains information about the intended URL and the HTTP verb (POST, GET). Therefore, to get a PoP token you will provide to MSAL an `HttpRequestMessage` and MSAL.NET will populate the Authorization header of this message with a PoP token. You'll need to:
225
+
With PoP, the programming model is a bit different from the way MSAL.NET usually works. A PoP token contains information about the intended URL and the HTTP verb (POST, GET). Therefore, to get a PoP token you will provide to MSAL an `HttpRequestMessage` and MSAL.NET will populate the Authorization header of this message with a PoP token.
226
+
227
+
In `Program.cs`, You'll need to:
226
228
227
229
- Instantiate a `IPublicClientApplication` specifying `WithExperimentalFeatures()`, as PoP is still an experimental feature for MSAL.NET (and implemented for only public client applications on .NET Framework).
0 commit comments