我们如何在 SignalR 中执行基于 OWIN oAuth Bearer 令牌的身份验证和授权? [英] How do we preform OWIN oAuth Bearer token based Authentication and Authorization in SignalR?

查看:37
本文介绍了我们如何在 SignalR 中执行基于 OWIN oAuth Bearer 令牌的身份验证和授权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用内置的 OWIN oAuth 服务器功能来生成不记名令牌.我们让他们使用 ASP.NET Web API,但不确定如何让他们使用 SignalR(和 AngularJS javscript 客户端).我们如何使用带有 SignalR 的 Bearer 令牌进行身份验证和授权?我还没有看到任何关于如何实现这一目标的明确明确的答案.

We are using the built in OWIN oAuth server functionality to generate Bearer tokens. We have them working with ASP.NET Web API but not sure how to get them working with SignalR (and an AngularJS javscript client). How do we use Bearer tokens with SignalR for authentication and authorization? I have not seen any really good clear answers on how to achieve this.

提前致谢.

推荐答案

遗憾的是,JS WebSocket API 无法设置自定义标头.

Unfortunately, the JS WebSocket API does not make it possible to set custom headers.

但是,应该可以将不记名令牌添加到 所有 SignalR 请求的查询字符串,其中包括 WebSocket 请求.

However, it should be possible to add the bearer token to the query string of all SignalR requests which includes the WebSocket requests.

$.connection.hub.qs = { 'access_token' : accessToken };

完成此操作后,您可以创建一个 自定义 OAuthBearerAuthenticationProvider 以提取来自查询字符串的令牌.

Once you do this, you could create a custom OAuthBearerAuthenticationProvider to pull the token from the querystring.

这篇关于我们如何在 SignalR 中执行基于 OWIN oAuth Bearer 令牌的身份验证和授权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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