【发布时间】:2017-01-09 09:44:15
【问题描述】:
有没有办法在 web api 项目中读取/解密不记名令牌?
我的 web api 还托管 SignalR 集线器,这些集线器通过 websocket 从浏览器调用。 与我的普通 api 调用不同,我无法在此处添加授权标头。虽然我可以在查询字符串中发送令牌并在 SignalR 集线器中读取它。
默认情况下,令牌由 owin 解析为声明身份。我需要的是手动执行此操作。我该怎么做?
OAuthAuthorizationServerOptions serverOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(Config.TokenLifetime),
Provider = new AuthProvider()
};
// Token Generation
app.UseStageMarker(PipelineStage.Authenticate); // wait for authenticate stage, so we get the windows principle for use with ntlm authentication
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
app.UseOAuthAuthorizationServer(serverOptions);
【问题讨论】:
-
您是否使用 OAuthBearerAuthenticationOptions 来生成令牌?
-
一种方法是将身份验证提供程序存储在 owin 启动类的静态变量中,并在需要从令牌中获取声明时调用它。
-
@Nikola.Lukovic:是的
-
我刚刚将我的配置添加到帖子中
-
@VinceBlack 检查尼古拉斯的回答:)
标签: c# asp.net-web-api signalr bearer-token