title: Null Context.User
body: <p>When I try to access Context.User in my Hub I keep getting Context.User is null errors. I have tried moving app.MapSignalR() under the ConfigureAuth() but that causes SignalR not to map at all. I'm not sure where I need to pass my cookie to SignalR at. </p>
  
  <p>SignalR is working in my app for sending messages to all users I just can't get the OnConnect override to work without the Context.User</p>
  
  <p>Startup.CS</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          app.MapSignalR();
          ConfigureAuth(app);
  
      }
  }
  </code></pre>
  
  <p>Startup.Auth.cs</p>
  
  <pre><code>public partial class Startup
  {
      private static string clientId =       ConfigurationManager.AppSettings["ida:ClientId"];
      private static string appKey = ConfigurationManager.AppSettings["ida:ClientSecret"];
      private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
      private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"];
      private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
      private static string authority = aadInstance + tenantId;
  
      public void ConfigureAuth(IAppBuilder app)
      {
  
          app.MapWhen(context =&gt; !IsDataPath(context.Request), appBuilder =&gt;
          {
              appBuilder.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
              appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions());
  
              appBuilder.UseOpenIdConnectAuthentication(
                  new OpenIdConnectAuthenticationOptions
                  {
                      //AuthenticationMode = AuthenticationMode.Passive,
                      ClientId = clientId,
                      Authority = authority,
                      PostLogoutRedirectUri = postLogoutRedirectUri,
  
                      Notifications = new OpenIdConnectAuthenticationNotifications()
                      {
                          SecurityTokenValidated = (context) =&gt;
                          {
                              var claimsIdentity = context.AuthenticationTicket.Identity;
                              CleanupClaims(claimsIdentity);
                              AddHboClaims(claimsIdentity);
                              context.AuthenticationTicket.Properties.ExpiresUtc = DateTime.Now.AddDays(1).ToUniversalTime();
                              return Task.CompletedTask;
                          },
                          AuthenticationFailed = (context) =&gt;
                          {
                              if (context.Exception.Message.StartsWith("OICE_20004") || context.Exception.Message.Contains("IDX10311"))
                              {
                                  context.SkipToNextMiddleware();
                                  return Task.FromResult(0);
                              }
                              return Task.FromResult(0);
                          },
                      }
                  });
          });
      }
  
      private bool IsDataPath(Microsoft.Owin.IOwinRequest request)
      {
          return request.Path.Value.StartsWith("/data");
      }
  
      private void CleanupClaims(ClaimsIdentity claimsIdentity)
      {
          //Remove long unecessary claim types to make the cookie smaller
          claimsIdentity.RemoveClaim(ClaimTypes.Surname);
          claimsIdentity.RemoveClaim(ClaimTypes.GivenName);
          claimsIdentity.RemoveClaim("onprem_sid");
          claimsIdentity.RemoveClaim("http://schemas.microsoft.com/identity/claims/tenantid");
          claimsIdentity.RemoveClaim("http://schemas.microsoft.com/claims/authnmethodsreferences");
          claimsIdentity.RemoveClaim("ipaddr");
      }
  
      private void AddHboClaims(ClaimsIdentity claimsIdentity)
      {
          var depResolver = AutofacDependencyResolver.Current;
          var permissionRespository = (IUserPermissionsRepository)depResolver.GetService(typeof(IUserPermissionsRepository));
          var emailClaim = claimsIdentity.FindFirst(ClaimTypes.Upn);
          var userPermissions = permissionRespository.GetPermissionForUser(emailClaim.Value);
          foreach (var permission in userPermissions)
          {
              claimsIdentity.AddClaim(HboClaimsNames.Permission, ((int)permission).ToString());
          }
  
          var db = (Database.HboDbContext)depResolver.GetService(typeof(Database.HboDbContext));
          var resource = db.Resources.SingleOrDefault(r =&gt; r.HmbEmail == emailClaim.Value);
          if (resource != null)
          {
              //if (resource.IsActive)
              //{
                  claimsIdentity.AddClaim(HboClaimsNames.ResourceId, resource.Id.ToString());
              //}
              //else
              //{
              //    var ex = new Exception("Inactive user attempting to log into HBO: " + emailClaim.Value);
              //    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
              //    
              //}
          }
          else
          {
              var ex = new Exception("User attempting to log into HBO that is not in Db: " + emailClaim.Value);
              Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
          }
      }
  }
  </code></pre>