title: How to authorize SignalR Core Hub method with JWT
body: <p><em>I am using JWT authentication in my ASP.NET Core 2.0 application with OpenIddict.</em>  </p>
  
  <p>I am following idea in <a href="https://github.com/aspnet/SignalR/issues/888" rel="nofollow noreferrer">this thread</a> and calling <code>AuthorizeWithJWT</code> method after SignalR handshake. But now, I do not know what should I set in <code>AuthorizeWithJWT</code> method so I can use <code>[Authorize(Roles="Admin")]</code> for example.</p>
  
  <p>I tried with setting context user, but it is readonly:</p>
  
  <pre><code>public class BaseHub : Hub
  {    
      public async Task AuthorizeWithJWT(string AccessToken)
      {
          //get user claims from AccesToken
          this.Context.User = user;  //error User is read only
      }
  }
  </code></pre>
  
  <p>And using authorize attribute:</p>
  
  <pre><code>public class VarDesignImportHub : BaseHub
  {
      [Authorize(Roles = "Admin")]
      public async Task Import(string ConnectionString)
      {
      }
  }
  </code></pre>