[英]SignalR and OpenId Connect
I have a server which uses ASP.NET Core Web Api
and OpenIddict
as authorization framework. 我有一台使用ASP.NET Core Web Api
和OpenIddict
作为授权框架的服务器。 Now I've added an SignalR
host and want to add authorisation to it. 现在,我添加了SignalR
主机,并希望向其添加授权。
From different sources I found that SignalR
(JS Client) wants that you send the access token in the querystring or by cookie as websockets don't support headers. 从不同的来源,我发现SignalR
(JS客户端)希望您以查询字符串或cookie的形式发送访问令牌,因为websocket不支持标头。
As the authentication middleware doesn't check the querystring or cookie container for an authorization entry I need to implement such an provider/retriever/resolver which reads this value by myself. 由于身份验证中间件不检查授权条目的查询字符串或cookie容器,因此我需要实现这样的提供程序/获取者/解析器,该提供程序/获取者/解析器自己读取该值。
I've found a solution for IdentityServer
but nothing about OpenIddict
. 我找到了IdentityServer
的解决方案,但没有OpenIddict
的解决方案 。
Where/How do I implement such an token resolver with OpenIddict
? 我在哪里/如何使用OpenIddict
实现这样的令牌解析器?
If you use JwtBearerAuthentication
then you can use OnMessageReceived
to set token: 如果你使用JwtBearerAuthentication
那么你可以使用OnMessageReceived
设置令牌:
Events = new JwtBearerEvents()
{
OnMessageReceived = async (ctx) =>
{
ctx.Token = ctx.Request.Query["<qs-name>"];
}
}
Or if you use IdentityServerAuthentication
then you can use TokenRetriever
(not tested but it should be something like this): 或者,如果您使用IdentityServerAuthentication
则可以使用TokenRetriever
(未经测试,但应该是这样的):
TokenRetriever = (ctx) =>
{
return ctx.Request.Query["<qs-name>"];
}
Just like @adem-caglin mentioned, in IdentityserverAuthentication you use TokenRetriever and can go with the built-in functions if what you're after is the standard bearer header or a query string 就像@ adem-caglin提到的那样,在IdentityserverAuthentication中,您使用TokenRetriever,并且如果要使用的是标准承载头或查询字符串,则可以使用内置函数
TokenRetriever = (request) =>
{
// by default calls TokenRetrieval.FromAuthorizationHeader()(request);
// check if request is to signalr endpoint and only then apply FromQueryString
return TokenRetrieval.FromQueryString()(request);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.