vos*_*d01 5 c# authentication cookies owin openid-connect
如何从Microsoft基于OWIN的中间件生成的cookie中检索OpenID连接令牌?
我正在使用Microsoft.Owin.Security.Cookies
并Microsoft.Owin.Security.OpenIdConnect
使用"隐含流"来保护网站.有时我认为我可能能够更好地理解事物或者能够排除故障我可以检查"原始"令牌而不是从它产生的对象模型.
我知道这些信息是通过Cookie存储的,但还没有找到我如何从cookie中检索令牌.这是一个开发环境,因此我应该可以访问所需的任何证书/机密.
我知道令牌应该有3个以句号分隔的段:{header}.{claims}.{signature}
.如果我能找到令牌,我就知道我可以使用jwt.io来查看内容.但是,我的cookie都没有与该格式匹配的内容.
这是我正在使用的中间件配置:
app.SetDefaultSignInAsAuthenticationType( CookieAuthenticationDefaults.AuthenticationType );
app.UseCookieAuthentication( new CookieAuthenticationOptions() );
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = stsAuthority,
RedirectUri = baseHostingPath,
ResponseType = "id_token",
Scope = string.Join( " ", "openid", "profile", "email" )
} );
Run Code Online (Sandbox Code Playgroud)
小智 9
如果你想在调试时这样做,我建议尝试https://github.com/vibronet/OInspector/tree/dev-它可以帮助你检查Fiddler中的令牌.
如果要在代码中执行此操作,可以确保将原始令牌保存在ClaimsPrincipal中
添加
TokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true
}
Run Code Online (Sandbox Code Playgroud)
到选项初始化
通过某些东西检索令牌
var ci = (System.Security.Claims.ClaimsIdentity)
ClaimsPrincipal.Current.Identity;
string token = ((System.IdentityModel.Tokens.BootstrapContext)
ci.BootstrapContext).Token;
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
3859 次 |
最近记录: |