Search code examples
asp.net-corejwtmicroservicesbearer-tokenasp.net-core-signalr

How to get the bearer token in the Asp .Net Core SignalR Hub?


I need access to the bearer token raw string (the token itself) in the Asp.Net Core SignalR Hub.

I need it because i have to use it when I'm making HttpClient Call to other microservice that requires the token from my hub.

I tried to create Per-request service that has Token property, but SignalR does not use Per-Request pattern. The token is sent only when client is connecting, and not always.

Anyway I need to get access to the bearer token and don't know how. Please help.


Solution

  • I need access to the bearer token raw string (the token itself) in the Asp.Net Core SignalR Hub.

    If you configure and use bearer token authentication for your ASP.NET Core SignalR App, to access the token that client provided within your hub method, you can try:

     var accessToken = Context.GetHttpContext().Request.Query["access_token"];
    

    Test Result

    enter image description here