简体   繁体   中英

JWT authentication in SignalR Core from Angular

The post is almost duplicate as this question, but I am using new SignalRCore (1.0.0 alpha2).
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-alpha2-final" />

In my .NET Core 2.0 I use OpenIddict to authenticate user on server. On client I use angular2-jwt .

Now I need to know how can I connect on server with Authorization header access_token ? I would assume that I should use custom request header when trying to connect on server.

Can this be done with new SignalR Core? I found this thread which mention that websockets does not support custom headers but I wonder if SignalR Core team did some magic to support this scenario.

This is not possible when you are using JavaScript client because some underlying APIs (like webSocket) don't allow setting headers. This is why you need to use queryString. Also, this thread on github may be useful.

If you are using the C# client setting headers is not possible at the moment but this is just a limitation of the API and should be fixed in the future.

EDIT

SignalR now has API that allows to pass JWT token to both C# and JavaScript client. It is also now possible to set headers when using C# client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM