-->

ServiceStack Javascript JsonServiceClient missing

2020-04-18 06:41发布

问题:

I am trying to connect to a JWT authenticated service using the Servicestack JsonServiceClient, however the Docs only describe how to do this using the C# client:

http://docs.servicestack.net/jwt-authprovider

In these docs, it indicates there should be a BearerToken property on the client like so:

var client = new JsonServiceClient(baseUrl) {
    BearerToken = jwtToken
};

However this seems to be missing on the Javascript Client. How can I assign the jwtToken when using the Javascript client?

I have tried the following variations to get this to work:

var jwtToken = this.auth.getAccessToken();
this.client = new JsonServiceClient('/');

// Variation #1
this.client.headers.append("Authentication" , jwtToken,);

// Variation #2
this.client.headers.append("Authentication" , "Bearer " + jwtToken,);

// Variation #3
this.client.headers.append("Authentication" , "BearerToken " + jwtToken,);

回答1:

Victory!

My mistake was the header name. It's not "Authentication" it's "Authorization".

So this works:

this.client.headers.append("Authorization" , "Bearer " + jwtToken,);