Token Based Authentication on Postman

1.5k views Asked by At

I am trying to send a request using a authentication token using Postman. I can successfully login from it and get the token. After that, when I try to send a request to a Authenticate method, it returns me a 401 - Unauthorized.

In the error definition, it says "The signature is invalid".

How I send a login request:

Login Request

Here what it returns after logging in on postman :

{
    "state": 1,
    "msg": null,
    "data": {
        "requestAt": "2017-08-27T23:44:18.1397478+03:00",
        "expiresIn": 2400,
        "tokenType": "Bearer",
        "accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InVzZXIxIiwiSUQiOiIxMTYwYzg1YS0yMmVkLTQ2N2YtYThjNC05NTk4NmMyNTcyMGYiLCJuYmYiOjE1MDM4NjY2NjAsImV4cCI6MTUwMzg2OTA1OCwiaWF0IjoxNTAzODY2NjYwLCJpc3MiOiJNeUlzc3VlciIsImF1ZCI6Ik15QXVkaWVuY2UifQ.m9q84OVsei19_3zdDSZMfGDsNqotBr6L6xf1e5aJq9OmTE5ZfqJ9k2l84cbMuge4qvABxId_h7QUZT0pI_vqEqohTfhaF2kDloqXEWawN0LTDUdeJt6xqT3W9AWmvmnDFrehM6HOeStNGKqG8955OHnwHyEiYn6AIaqg4Sm6I87xk1C5aBhyfkV6-We-Wfj0W4NSg7_2LOIF6TApsnV8VF34PB5VATER9-g-dVUE0E_q4UmLFYD6lkudAXbA4Oa3iTXJKhLCL4NhacBXYXGN-ZyGwX64F7dWPw_mI8Q_AHpHkSrb4m5pscvgvo0leGRGVmuWuCP__rAZpw1EnLmTiQ"
    }
}

This is the method I am requesting after the login method :

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpGet]
public IActionResult GetUserInfo()
{
   var claimsIdentity = User.Identity as ClaimsIdentity;
   return Json(new RequestResult
   {
      State = RequestState.Success,
      Data = new { UserName = claimsIdentity.Name }
   });
}

And this is how I send a request to GetUserInfo method :

Get request

Lastly my TokenAuthOptions class :

public class TokenAuthOption
{
    public static string Audience { get; } = "MyAudience";
    public static string Issuer { get; } = "MyIssuer";
    public static RsaSecurityKey Key { get; } = new RsaSecurityKey(RSAKeyHelper.GenerateKey());
    public static SigningCredentials SigningCredentials { get; } = new SigningCredentials(Key, SecurityAlgorithms.RsaSha256Signature);
    public static TimeSpan ExpiresSpan { get; } = TimeSpan.FromMinutes(40);
    public static string TokenType { get; } = "Bearer"; 
}
0

There are 0 answers