Oauth 2.0 使用SignalR通知连接的客户端新登录Web.API

Oauth 2.0 使用SignalR通知连接的客户端新登录Web.API,oauth-2.0,signalr,asp.net-web-api2,signalr-hub,Oauth 2.0,Signalr,Asp.net Web Api2,Signalr Hub,我有一套使用ASP.NET Web API 2开发的现有API。目前,用户需要在使用大多数API之前进行身份验证(少数是公共的)。这是我缩小的OAuthProvider public class MyOAuthProvider : OAuthAuthorizationServerProvider { // Validation of user name and password takes place here // Code not show for brevity // If u

我有一套使用ASP.NET Web API 2开发的现有API。目前,用户需要在使用大多数API之前进行身份验证(少数是公共的)。这是我缩小的OAuthProvider

public class MyOAuthProvider : OAuthAuthorizationServerProvider
{
  // Validation of user name and password takes place here
  // Code not show for brevity
  // If user is validated issue then issue them a JWT token 

  ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, "JWT");

  var ticket = new AuthenticationTicket(oAuthIdentity, null);

  context.Validated(ticket);
}
在另一个应用程序中,我对signar进行了实验,并使用了一个Hub类,该类获取用户的connectionId和userName,并将其存储到名为
connectionDictionary
的内存字典中

public class ChatHub : Hub
{
    public static Dictionary<string,string> connectionDictionary = new Dictionary<string, string>();

    public override Task OnConnected()
    {
        connectionDictionary.Add(Context.ConnectionId, Context.User.Identity.Name);
        return base.OnConnected();
    }
}
公共类聊天中心:中心
{
公共静态字典connectionDictionary=新字典();
已连接的公用覆盖任务()
{
Add(Context.ConnectionId,Context.User.Identity.Name);
返回base.OnConnected();
}
}

我如何将这些连接在一起,以便当用户使用API进行身份验证时,他们的connectionId和用户名存储在字典中?其想法是,一旦用户登录,我将通知所有其他连接的客户端。

我不知道我是否理解正确,是否要使用身份验证令牌连接到信号集线器,然后使用令牌中的身份信息在内存字典中注册用户?我不知道我是否理解正确,是否要使用身份验证令牌连接到信号集线器,然后使用令牌中的标识信息在内存字典中注册用户?