GetAccessToken value cannot be null: RefreshToken OR jwtPayload

We’ve recently (in the last few months) updated to the latest ServiceStack, but strange errors have started appearing when restarting an app / other random times.

The error:

    {
  "responseStatus": {
    "errorCode": "ArgumentNullException",
    "message": "Value cannot be null.\r\nParameter name: RefreshToken",
    "stackTrace": "[GetAccessToken: 5/7/2019 7:27:14 PM]:\n[REQUEST: {}]\nSystem.ArgumentNullException: Value cannot be null.\r\nParameter name: RefreshToken\r\n   at ServiceStack.Auth.GetAccessTokenService.Any(GetAccessToken request) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Auth\\JwtAuthProvider.cs:line 401\r\n   at ServiceStack.Host.ServiceRunner`1.ExecuteAsync(IRequest req, Object instance, TRequest requestDto) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Host\\ServiceRunner.cs:line 133",
    "errors": [
      {
        "errorCode": "ArgumentNullException",
        "fieldName": "RefreshToken",
        "message": "Value cannot be null.\r\n"
      }
    ]
  }
}

Sometimes the error is:

{
  "responseStatus": {
    "errorCode": "ArgumentNullException",
    "message": "Value cannot be null.\r\nParameter name: jwtPayload",
    "stackTrace": "[GetAccessToken: 5/8/2019 3:26:19 PM]:\n[REQUEST: {refreshToken:eyJ0eXAiOiJKV1RSIiwiYWxnIjoiSFMyNTYiLCJraWQiOiJ2KzEifQ.eyJzdWIiOjEsImlhdCI6MTU1NzI1ODQzNiwiZXhwIjoxNTg4Nzk0NDM2fQ.kD9Fz8e0VG2BQ3S7dl91u3kj3nYTGGQ2PUeXIQe3t1Y}]\nSystem.ArgumentNullException: Value cannot be null.\r\nParameter name: jwtPayload\r\n   at ServiceStack.Auth.JwtAuthProviderReader.GetInvalidJwtPayloadError(JsonObject jwtPayload) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Auth\\JwtAuthProviderReader.cs:line 613\r\n   at ServiceStack.Auth.JwtAuthProviderReader.AssertJwtPayloadIsValid(JsonObject jwtPayload) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Auth\\JwtAuthProviderReader.cs:line 595\r\n   at ServiceStack.Auth.GetAccessTokenService.Any(GetAccessToken request) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Auth\\JwtAuthProvider.cs:line 398\r\n   at ServiceStack.Host.ServiceRunner`1.ExecuteAsync(IRequest req, Object instance, TRequest requestDto) in C:\\BuildAgent\\work\\3481147c480f4a2f\\src\\ServiceStack\\Host\\ServiceRunner.cs:line 133",
    "errors": [
      {
        "errorCode": "ArgumentNullException",
        "fieldName": "jwtPayload",
        "message": "Value cannot be null.\r\n"
      }
    ]
  }
}

Our client setup is pretty straight forward: (client.js)

import { JsonServiceClient } from '@servicestack/client';
const client = new JsonServiceClient(API_URL);
export const setToken = (bearerToken, refreshToken) => {
  client.bearerToken = bearerToken;
  client.refreshToken = refreshToken;
};
export default client;

Will all of the calls using client.js, I see the Bearer populated in the header. Any idea why this might be happening?

We may have discovered the fix, currently testing.

While we haven’t used JWT much, I think SS uses JWT under the hood for various token-y things. We were setting the AuthKeyBase64 to AesUtils.CreateKey(), which is invalidating everything on restart. Setting this to a pre-determined value seems to have fixed it (pushing out a new deploy now for testing).

1 Like