Ignore JWT Bearer token signature (i.e. don't validate token)

后端 未结 3 1940
鱼传尺愫
鱼传尺愫 2021-02-05 17:20

I have an API that sits behind an API Gateway. The API Gateway validates the bearer token before passing the request along to the API.

My API the uses the the asp.net co

3条回答
  •  悲哀的现实
    2021-02-05 17:34

    Try this. Finally, I got it to work after so much of trying.

    public TokenValidationParameters CreateTokenValidationParameters()
    {
        var result = new TokenValidationParameters
        {
        ValidateIssuer = false,
        ValidIssuer = ValidIssuer,
    
        ValidateAudience = false,
        ValidAudience = ValidAudience,
    
        ValidateIssuerSigningKey = false,
        //IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(SecretKey)),
        //comment this and add this line to fool the validation logic
        SignatureValidator = delegate(string token, TokenValidationParameters parameters)
        {
            var jwt = new JwtSecurityToken(token);
    
            return jwt;
        },
    
        RequireExpirationTime = true,
        ValidateLifetime = true,
    
        ClockSkew = TimeSpan.Zero,
        };
    
        result.RequireSignedTokens = false;
    
        return result;
    }
    

提交回复
热议问题