OpenIddict Core with SignalR
See original GitHub issueI’ve been looking all over, and cannot figure out how to get the access token from a query string to be used with Signalr. Could somebody by chance help provide an example?
I’ve tried doing both this:
.AddValidation(options =>
{
options.AddEventHandler<OpenIddictValidationEvents.RetrieveToken>(
notification =>
{
notification.Context.Token = notification.Context.Request.Query["access_token"];
return Task.CompletedTask;
});
});
and this:
services.AddAuthentication()
.AddOAuthValidation(options =>
{
options.Events.OnRetrieveToken = context =>
{
context.Token = context.Request.Query["access_token"];
return Task.CompletedTask;
};
});
in my Startup.cs file (as found in another issue here)
Is there something I am missing? I’m using .net core 2.1. Thank you so much in advance for any help! I’ve been stuck on this for quite a while.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
SignalR with openiddict user claims with react
I'm currently working on a project with a react client and asp.net server. I was tryin to add authorization to the signalR requests...
Read more >OpenIddict for Securing ASP.NET Core — Virto Tech Study
Openiddict is an open-source framework used to build servers in ASP.NET Core applications. It fully complies with OAuth 2.0 and OpenID Connect and...
Read more >Implementing OpenID Code Flow with PKCE using OpenIddict ...
This article shows how to implement the OpenID Connect Code Flow with PKCE using OpenIddict hosted in an ASP.NET Core application, an ASP....
Read more >Secure a Blazor WASM ASP.NET Core hosted APP using BFF ...
OpenIddict is used to implement the OpenID Connect server application. The code flow with PKCE and a user secret is used for authentication....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay I feel a little stupid, and finally figured this out (ironically pretty quickly after posting the issue). The key is that if you add to the OAuthValidation options - in services.AddOauthValidation(options => …), then you must completely comment out the .AddValidation(); after .AddServer in services.AddOpenIddict();
For example here’s a sample of working code, that does not use JWT tokens:
Now the access_token in the query string will work to authenticate your users with Signalr - by placing the [Authorize(AuthenticationSchemes = OAuthValidationDefaults.AuthenticationScheme)] above the Hub class, just as you would in the Controller.
@kevinchalet likewise, I recently discovered
OpenIddict
and it has been great! Very nice Examples repo too, made it super easy to get up and running. Thank you for your work on it!