Alternative access token query key for SignalR bearer authentication
See original GitHub issueI have a custom authentication flow that involves attaching an access token to the headers/query string using a “token” key (url: ...?token={my-token}
). I was able to set query strings on the old signalr ASP.NET JS client as the documentation states:
var connection = $.hubConnection(); connection.qs = { 'version' : '1.0' };
https://github.com/SignalR/bower-signalr/blob/bdc7cb4b255e41acf09a18f646a14732c163fcbb/jquery.signalR.js#L146-L153
However, the ASP.NET Core package version restricts (or rather standardizes) access tokens to be passed only through a “access_token” key:
I believe it is due to the standard, but being able to set the key through IHttpConnectionOptions of the builder would be nice. something like:
HubConnectionBuilder().withUrl("/hubs/chat", { accessTokenFactory: () => this.loginToken, accessTokenKey: 'my-key' })
Alternatively, being able to set query string parameters (as in the old package) would be a great too.
Any thoughts on the idea? I would be glad to make a PR for this feature.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
@mikeChatsky That sounds like the best approach for now. I do recognize the value of being able to change the query string option but I’m not yet sure it’s worth the overhead of new public options APIs. We can keep an eye out for other cases where users can’t refactor quite so easily and revisit this in the future.
Couldn’t you also just do this by setting a query string token in the URL or using a header? Like this:
If you need to “refresh” it with new values, you could also provide a custom
HttpClient
implementation by setting thehttpClient
property.