我试图为另一个adfs生成一个ActAs令牌,但我登录的第一个ADFS并不会返回SecurityToken。 我在OWIN Startup上错过了一些配置吗?
Startup.cs
public SecurityToken GetSecuritySAMLToken()
{
ClaimsPrincipal icp = Thread.CurrentPrincipal as ClaimsPrincipal;
ClaimsIdentity claimsIdentity = (ClaimsIdentity)icp.Identity;
BootstrapContext bootstrapContext = claimsIdentity.BootstrapContext as BootstrapContext;
//bootstrapContext is not null and bootstrapContext.Token is not null, however bootstrapContext.SecurityToken is null
return bootstrapContext.SecurityToken;
}
我如何检索令牌:
public SecurityToken GetSecuritySAMLToken()
{
ClaimsPrincipal icp = Thread.CurrentPrincipal as ClaimsPrincipal;
ClaimsIdentity claimsIdentity = (ClaimsIdentity)icp.Identity;
BootstrapContext bootstrapContext = claimsIdentity.BootstrapContext as BootstrapContext;
return GetSecurityTokenFromStringToken(bootstrapContext);
}
private static SecurityToken GetSecurityTokenFromStringToken(BootstrapContext bootstrapContext)
{
var handler = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
SecurityToken ST = handler.ReadToken(bootstrapContext.Token);
return ST;
}
更新1
尝试将字符串(SAMLToken)转换为SecurityToken,handler.ReadToken返回null。
pickle.dump(variable, gzip.open(file_name, 'wb'), -1)
答案 0 :(得分:0)
不得不这样回复:
private static SecurityToken GetSecurityTokenFromStringToken(BootstrapContext bootstrapContext)
{
Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler handler = new Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler();
handler.Configuration = new Microsoft.IdentityModel.Tokens.SecurityTokenHandlerConfiguration();
XmlReader reader = XmlReader.Create(new StringReader(bootstrapContext.Token));
SecurityToken samlToken = handler.ReadToken(reader);
return samlToken;
}