ServiceStack Javascript JsonServiceClient missing properties

廉价感情. 提交于 2019-12-02 14:41:33

问题


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,);


来源:https://stackoverflow.com/questions/42568936/servicestack-javascript-jsonserviceclient-missing-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!