title: Passing JWT Token as QueryString to SignalR Hub
body: <p>Trying to follow the suggestions in the link below to pass a <code>JWT</code> token to my SignalR hub but so far it's not working. In particular, see David Fowler's suggestion on July 22, 2017. <a href="https://github.com/aspnet/SignalR/issues/130" rel="nofollow noreferrer">https://github.com/aspnet/SignalR/issues/130</a></p>
  
  <p>My frontend is <code>React</code> so I'm simply adding the token to the querystring as follows where <code>_token</code> has my <code>JWT</code> token value:</p>
  
  <pre><code>const connection = new signalR.HubConnectionBuilder()
      .withUrl("/myhub?AUTHORIZATION=" + _token)
      .configureLogging(signalR.LogLevel.Information)
      .build();
  </code></pre>
  
  <p>In the <code>ConfigureServices()</code> method of my <code>Startup.cs</code>, I have the following configuration for <code>Jwt</code> tokens:</p>
  
  <pre><code>services.AddAuthentication(options =&gt; {
                  options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
              })
                .AddJwtBearer(jwtOptions =&gt; {
                    jwtOptions.Authority = $"https://login.microsoftonline.com/tfp/{Configuration["AzureAdB2C:Tenant"]}/{Configuration["AzureAdB2C:Policy"]}/v2.0/";
                    jwtOptions.Audience = Configuration["AzureAdB2C:ClientId"];
                    jwtOptions.Events = new JwtBearerEvents
                    {
                        OnMessageReceived = context =&gt;
                        {
                            if(context.HttpContext.WebSockets.IsWebSocketRequest)
                                context.Token = context.Request.Query["AUTHORIZATION"];
  
                            return Task.CompletedTask;
                        }
                    };
                });
  </code></pre>
  
  <p>And this is what my <code>Hub</code> looks like:</p>
  
  <pre><code>[Authorize]
  public class MyHub : Hub
  {
     private IBackendService _backendService;
     public MyHub(IBackendService backendService)
     {
         _backendService = backendService;
     }
  
     public async Task SendMessage(string message)
     {
         // Regular SignalR stuff
         // SignalR will now send the message to all connected users...
     }
  }
  </code></pre>
  
  <p>Basically, I'm getting the <code>401 Unauthorized</code> error.</p>
  
  <p>I put a break point where I check to see if the request is a web sockets request but I'm not hitting it. Looks like something in the pipeline is determining that the user is not authenticated.</p>
  
  <p>What am I doing wrong in my code?</p>