简体   繁体   English

SignalR和OpenId Connect

[英]SignalR and OpenId Connect

I have a server which uses ASP.NET Core Web Api and OpenIddict as authorization framework. 我有一台使用ASP.NET Core Web ApiOpenIddict作为授权框架的服务器。 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.

相关问题 何时不使用 OpenId 连接 - When not to use OpenId connect 如何从angularJs连接signalR - How to connect signalR from angularJs 使用 openid connect 保护公共 api - Securing a public api using openid connect 如果集线器位于不同的SignalR项目中,如何连接集线器? - How to connect Hub if Hub is in different project SignalR? 生成自己的 JWT Bearer 是否与 OAuth/OpenID Connect 相同? - Is generating your own JWT Bearer the same as OAuth/OpenID Connect? ASP.NET 使用外部 OpenID Connect 提供程序进行核心认证/授权 - ASP.NET Core authentication/authorization with external OpenID Connect provider 使用针对Azure Active Directory的OpenId Connect获取令牌 - Get Token Using OpenId Connect against Azure Active Directory 当混合应用程序连接到SignalR Hub时,获取“ConnectionId的格式不正确” - Getting 'The ConnectionId is in the incorrect format' when hybrid app connect to SignalR Hub ASP.NET Web API 和 OpenID Connect:如何从授权码获取访问令牌 - ASP.NET Web API and OpenID Connect: how to get Access Token from Authorization Code 我们可以在 ASP.NET (VB.NET) 中使用 oauth 来 openid 连接吗? - Can we use oauth to openid connect in ASP.NET (VB.NET )?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM