In the article we looked a aspects of authentication/authorization frameworks that can be used in COTS and bespoke applications. This article will look at Web API authentication using JWT. The sample source code can be obtained from here
The sample code will demonstrate the following scenario
The User data-model used in the sample application has the attributes as per table below
- Console App will invoke a post request with username and password to Gateway Api based on Ocelot api gateway and works well for Microservices architecture. In architecture pattern consisting of several microservices, ocelot provides a simple configurable end point to communicate with each microservice.
“/authentication/authenticate” > pointer to authentication controller and authenticate method within the microservice Web API.
The JSON file for Ocelot API will consists of ReRoutes specified as a combination of DownstreamPathTemplate and UpstreamPathTemplate.
The output of the Console App will be as per below, the returned JWT token will be in the format [Header].[Payload].[Signature]
If we decode the JWT token in the debugger at jwt.io we will get the user information.
Pingback: OAuth and OpenID Connect using IdentityServer | Information Dynamics