Not able to validate JSON Web Token with .NET – key too short

前端 未结 3 1058
清歌不尽
清歌不尽 2021-01-03 11:56

I have used JSONWebToken npm module to generate a jwt:

var jwt = require(\'jsonwebtoken\');

var payload = {
    \"iss\": \"https://secure.examp         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 12:30

    Try to use TextEncodings.Base64Url.Decode api from Microsoft.Owin.Security.Jwt package to decode the signing key

    Then I do following to validate token:

    var principal = new JwtSecurityTokenHandler().ValidateToken(jwtheader,
                            new TokenValidationParameters()
                            {
                                RequireExpirationTime = true,
                                ValidAudience = audience,
                                ValidIssuer = issuer,
                                IssuerSigningKey = new InMemorySymmetricSecurityKey(secret)
                            }, out token);
    

提交回复
热议问题