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
# How to manually validate a JWT access token using the Microsoft identity platform (formerly Azure Active Directory for developers)
20
+
# How to manually validate a JWT access token using the Microsoft identity platform
21
+
22
+
-[Overview](#overview)
23
+
-[About this sample](#about-this-sample)
24
+
-[Scenario: protecting a Web API - acquiring a token for the protected Web API](#scenario-protecting-a-web-api---acquiring-a-token-for-the-protected-web-api)
25
+
-[Token Validation](#token-validation)
26
+
-[What to validate?](#what-to-validate)
27
+
-[Validating the claims](#validating-the-claims)
28
+
-[Prerequisites](#prerequisites)
29
+
-[Setup](#setup)
30
+
-[Explore the sample](#explore-the-sample)
31
+
-[About The Code](#about-the-code)
32
+
-[How To Recreate This Sample](#how-to-recreate-this-sample)
33
+
-[Creating the TodoListService-ManualJwt Project](#creating-the-todolistservice-manualjwt-project)
34
+
-[Creating the TodoListClient Project](#creating-the-todolistclient-project)
35
+
-[How to deploy this sample to Azure](#how-to-deploy-this-sample-to-azure)
36
+
-[Azure Government Deviations](#azure-government-deviations)
37
+
-[Troubleshooting](#troubleshooting)
38
+
-[Community Help and Support](#community-help-and-support)
This sample demonstrates how to manually validate an access token issued to a web API protected by the Microsoft Identity Platform. Here a .NET Desktop App (WPF) calls a protected ASP.NET Web API that is secured using Azure AD.
47
+
15
48
## About this sample
16
49
17
50
A Web API that accepts bearer token as a proof of authentication is secured by [validating the token](https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens#validating-tokens) they receive from the callers. When a developer generates a skeleton Web API code using [Visual Studio](https://aka.ms/vsdownload), token validation libraries and code to carry out basic token validation is automatically generated for the project. An example of the generated code using the [asp.net security middleware](https://github.com/aspnet/Security) and [Microsoft Identity Model Extension for .NET](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet) to validate tokens is provided below.
@@ -205,7 +238,7 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
205
238
1. Open the `TodoListClient\App.Config` file.
206
239
1. Find the key `ida:Tenant` and replace the existing value with your Azure AD tenant name.
207
240
1. Find the key `ida:ClientId` and replace the existing value with the application ID (clientId) of `TodoListClient-ManualJwt` app copied from the Azure portal.
208
-
1. Find the key `todo:TodoListResourceId` and replace the value with the App ID URI you registered earlier, when exposing an API. For instance use `api://<application_id>`.
241
+
1. Find the key `todo:TodoListResourceId` and replace the existing value with the App ID URI you registered earlier, when exposing an API. For instance use `api://<application_id>`.
209
242
1. Find the key `todo:TodoListBaseAddress` and replace the existing value with the base address of `TodoListService-ManualJwt` (by default `https://localhost:44324`).
210
243
211
244
## Running the sample
@@ -214,9 +247,11 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
214
247
>
215
248
> Clean the solution, rebuild the solution, and run it. You might want to go into the solution properties and set both projects as startup projects, with the service project starting first.
216
249
250
+
## Explore the sample
251
+
217
252
Explore the sample by signing in, adding items to the To Do list, removing the user account, and starting again. Notice that 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 the sample implements a [persistent cache for MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/token-cache-serialization), and remembers the tokens from the previous run.
218
253
219
-
> 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.
254
+
> :information_source: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.
220
255
221
256
> [Consider taking a moment to share your experience with us.](https://forms.office.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbR73pcsbpbxNJuZCMKN0lURpUMjFRQjA0RElFUFNPV0dCUVBGQzk0QkhKTiQlQCN0PWcu)
// The ConfigurationManager class holds properties to control the metadata refresh interval. For more details, https://docs.microsoft.com/en-us/dotnet/api/microsoft.identitymodel.protocols.configurationmanager-1?view=azure-dotnet
// Please inspect TokenValidationParameters class for a lot more validation parameters.
137
-
};
149
+
// Refresh the metadata (cached keys) if the metadata refresh has invalidated the cache (https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki/Resilience-on-metadata-refresh)
0 commit comments