Hi @layoric,
Let me try to explain what I am looking for hoping I will succeed and you will able to guide me to the best possible direction. By the way your above response helped me out to achieve another mile but I need expert opinion.
Background
When a user authenticates using the username and password credentials upon successful authentication he receives bearerToken and refreshToken as shown below. Until the token is valid and not expired user is able to make API calls.
Successful Authenticated Response
{
"userId": "2",
"sessionId": "2XopRT7...",
"userName": "user1",
"displayName": "User 1",
"bearerToken": "eyJ0eXAiOiJKV1QiLC...",
"refreshToken": "eyJ0eXAiOiJKV1RSIiw...",
"profileUrl": "data:imag",
"roles": [],
"permissions": []
}
Requirements
I am trying to standardize the response. In these 2 cases
-
When the token is expired
-
When the user is trying to use a token which is not valid.
Token Expired Case:
When the token is expired ServiceStack is throwing this response
{
"responseStatus": {
"errorCode": "TokenException",
"message": "Token has expired",
"stackTrace": "ServiceStack.TokenException: Token has expired\r\n at ServiceStack.Auth.JwtAuthProvi........",
"errors": []
}
}
This is the desired response I want to send to user along with the Http Status Code 401 what ServiceStack is already throwing
{
"errorCode": "401",
"message": "Token Expired"
}
Invalid Token Case
When the user is using invalid token there is no response body being thrown by ServiceStack. Only 401 Unauthorized Http Status Code.
Like Case 1, I want to control the response and want to throw the standard response like this
{
"errorCode": "401",
"message": "Invalid Token"
}
I hope I didn’t give you headache by writing such a long text. Apologize if my question is very basic as due to limited knowledge I am trying to progress.
Regards,