IdentityServer ClientCredentials with POSTMAN

This tutorial will demonstrate how to set up security within microservices using IdentityServer with OpenID. This will use a Client and Secret for microservice to microservice (machine-to-machine) communication that way a compromised microservice can’t interact with resources it’s not authorized to. I will also demonstrate how to use POSTMAN to get tokens, inspect tokens, and verify things are set up correctly.


GitHub: IdentityServer OpenID POSTMAN

What is OpenID Connect (OIDC)?

OpenID is a protocol that standardized OAuth and added certain capabilities to make authentication easier and more universal. OAuth is still responsible for handling authorization while OpenID is an extension that specifically standardizes authentication by providing login and profile information through a token known as the JWT token.

Setting Up the IdentityServer

This section will walk through creating the IdentityServer project and how to configure it for OpenID Connect.

Creating the Project

First, you’ll need to install the IdentityServer templates.

dotnet new -i identityserver4.templates

After the templates are installed you can create an IdentityServer project using dotnet new. If you want to use OAuth for authenticating users you can also add the UI which will include MVC controllers and views. This is not necessary for this tutorial.

Setting up API Resources, Clients in the Config.cs


Under the ConfigureService() method you will also need to add the Config.ApiResources to register them with the IdentityServer.

Add this line of code .AddInMemoryApiResources(Config.ApiResources).

Microservice API

The goal here is to protect a microservice API from internal abuse within the cluster by configuring JWT bearer verification. The general idea of protecting microservice-to-microservice (machine-to-machine) communication is to limit the amount of damage a bad actor could do if they hypothetically gain access to the cluster. This could be a hacker compromising a container and attempting to interact with other microservices to pivot or gain information.

Install NuGet Package


Configuring JWT Bearer Verification

There are several ways to set up JWT validation through .NET. I will demonstrate how to do this using the ASP.NET middleware libraries.

Startup.cs – ConfigureServices()

To apply authentication to the entire API it’s easiest to create an Authorization Policy and apply it as an AuthorizeFilter.

Startup.cs – Configure()

Add the code below to the Configure() method. If you skip this step or comment this out the IdentityServer will create a valid JWT token but it will still return unauthorized when using that valid token against the API service.

Using POSTMAN to Verify OpenID/OAuth Works

POSTMAN is a great tool for interacting with APIs and has full support for OpenID/OAuth.

Creating a GET Request

We will first need to set the URL to GET to https://localhost:5011/WeatherForecast You may need to update the ports here but this is the port for the microservice and can be found in the Properties of the project. This should fail with a 401 Unauthorized HTTP status response. This is as expected.

(401 Unauthorized)

Getting a Token

To get a JWT token (Bearer Token), you will need to select the Authorization Tab set it to OAuth 2, and configure it with the settings below. You may have to scroll down on the right to get to this section but look for “Configure New Token”. Be sure to set the Client ID, Secret, and Scopes requested.

The next window that will popup displays that the token has been generated and authorization with the IdentityServer was successful. Click “proceed” or just wait…

On the next screen you should copy the JWT Token so you can inspect it at

Great Success!

At this point the Bearer Token (JWT) is being sent along with the request to get WeatherForecasts and is successfully authenticating.

Inspecting Tokens

Inspecting the JWT Token is easy. Hop over to and paste in the JWT Token and you can see the properties passed with it.

Reserved Claims

These are the reserved claims that are used for OpenID to process and authenticate JWT tokens.

  • iss – Issuer of the JWT
  • sub – Subject of the JWT
  • aud – Audience (Defined under ApiResources in IdentityServer)
  • exp – Expiration time in Epoch time.
  • nbf – Not before time
  • iat – Issued at time
  • jti – Unique identifier for the JWT Token (JWT ID).

Further Reading