ServiceStack Javascript JsonServiceClient 缺少属性 [英] ServiceStack Javascript JsonServiceClient missing properties

查看:34
本文介绍了ServiceStack Javascript JsonServiceClient 缺少属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Servicestack JsonServiceClient 连接到经过 JWT 身份验证的服务,但是文档仅描述了如何使用 C# 客户端执行此操作:

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

在这些文档中,它表示客户端上应该有一个 BearerToken 属性,如下所示:

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

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

然而,这似乎在 Javascript 客户端上丢失了.使用Javascript客户端时如何分配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,);

推荐答案

胜利!

我的错误是标题名称.这不是身份验证",而是授权".

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

所以这是有效的:

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

这篇关于ServiceStack Javascript JsonServiceClient 缺少属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆