Verification token-based authorization identityserver4

problem:

  aspnetcore services injected into a shuttle, why is there such a demand?

  Because some programs are not aspnetcore, asp.net web api also want to access.

achieve:

  // need to refer to the package, the minimum support 4.5

  System.IdentityModel.Tokens.Jwt 5.6.0

  The main code

  // obtain the public key

     var json = httpclient acquired jwks;

  var = Ctte Microsoft.IdentityModel.Tokens.JsonWebKeySet.Create (json);

  // build parameter

       var parameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters ();
       parameter.IssuerSigningKeys jwk.GetSigningKeys = ();

  // Verify enacted by
       parameter.ValidIssuer = "http: // localhost: 5000";

  // verify that the resource
       parameter.ValidAudience = "api1";

       // verification token

  var claimsPrincipal = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler().ValidateToken(tokenString, parameter, out Microsoft.IdentityModel.Tokens.SecurityToken token);

Guess you like

Origin www.cnblogs.com/wh-blog/p/11843303.html