title: Assign/Push ClaimsPrincipal to SignalR Context
body: <p>Ok, So this one is certainly pushing me towards the edge of the cliff... Having worked with V1 of <code>SignalR</code> with relative ease, I'm certainly struggling now.</p>
  
  <p><strong>The Problem:</strong> "Grabbing" <code>Claims</code> from the recently authenticated user and passing/using in a <code>Hub</code></p>
  
  <p><strong>The Environment</strong>:</p>
  
  <p>WebAPI Authenticating with <code>Basic Auth</code> over <code>SSL</code>. The logic for authenticating is within an attribute and works fine and has been for months, it also generates/builds Claims within <code>AuthenticateAsync</code></p>
  
  <p>In my <code>API Controller</code> I grab the claims:</p>
  
  <pre><code>var idenityInstance = new IdentityInstance(this.User as ClaimsPrincipal);
  </code></pre>
  
  <p>I have spent the weekend trying to incorporate V2 of SignalR utilizing Groups/SSL and Authentication.</p>
  
  <p>I generally thought the ClaimsPrincipal would be passed over or in the same "Context".</p>
  
  <pre><code>            public void Configuration(IAppBuilder app)
              {
                  // Branch the pipeline here for requests that start with "/signalr"
                  app.Map("/signalr", map =&gt;
                  {
                      // Setup the CORS middleware to run before SignalR.
                      // By default this will allow all origins. You can 
                      // configure the set of origins and/or http verbs by
                      // providing a cors options with a different policy.
                      map.UseCors(CorsOptions.AllowAll);
                      var hubConfiguration = new HubConfiguration
                      {
                          // You can enable JSONP by uncommenting line below.
                          // JSONP requests are insecure but some older browsers (and some
                          // versions of IE) require JSONP to work cross domain
                          // EnableJSONP = true
                      };
                      // Run the SignalR pipeline. We're not using MapSignalR
                      // since this branch already runs under the "/signalr"
                      // path.
                      map.RunSignalR(hubConfiguration);
                  });
  
              }
  </code></pre>
  
  <p>Custom Authorize Attribute (Grabbed from the Docs)</p>
  
  <pre><code>        protected override bool UserAuthorized(System.Security.Principal.IPrincipal user)
          {
              if (user == null)
              {
                  throw new ArgumentNullException("user");
              }
  
              var principal = user as ClaimsPrincipal;
  
              if (principal != null)
              {
                  Claim authenticated = principal.FindFirst(ClaimTypes.Authentication);
                  if (authenticated != null &amp;&amp; authenticated.Value == "true")
                  {
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
              else
              {
                  return false;
              }
          }
  </code></pre>
  
  <p><strong>Ok, Last snippet, The Hub (stripped back)</strong></p>
  
  <pre><code>        public async Task Hello()
          {
              //Temp line for testing under local SSL/Self signed
              ServicePointManager.ServerCertificateValidationCallback
                  += (sender, cert, chain, sslPolicyErrors) =&gt; true;
  
              var hubConnection = new HubConnection("https://localhost:44357");
  
  
              IHubProxy chatHubProxy = hubConnection.CreateHubProxy("printerHub");
  
  
  
              hubConnection.Start().Wait();
              var c = Context;
              await hubContext.Clients.All.hello("Hello");
          }
  </code></pre>
  
  <p>Again the problem is when I debug through the <code>Hub Method Hello();</code> <code>Context</code> is always <code>null</code> and ultimately does not <code>authenticate</code> due to the custom <code>attribute</code></p>
  
  <p>I'm hoping I've just missed something silly here, because it's certainly very frustrating.</p>