有没有办法在web api项目中读取/解密不记名令牌?在Web API中解密承载令牌
我的web api还托管着通过websocket从浏览器调用的SignalR集线器。 与我的正常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:是的 –