Hot Chocolate GraphQL Custom Authentication Series Using Pure Code First Technique - Part3 -Validating JWT Token And Different Authorization Techniques
Part2 we had generated a JWT access token for the user authentication. In this article, we are going to validate the JWT access token and also understand different techniques of Authorization. Install JwtBearer NuGet: To enable jwt token validation service we have to install JwtBearer NuGet. Package Manager Command: Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 5.0.4 .Net CLI Command: dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer --version 5.0.4 Register JwtBearer Service: In the 'Startup.cs' file, we should register our JwtBearer validation service. Startup.cs: services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { var tokenSettings = Configuration .GetSection("TokenSettings").Get<TokenSettings>(); options.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = tokenSettings.Issuer, ValidateIssuer = true, ValidAudience = tokenSettings.Audienc