您可以从 ADFS 请求 DisplayTokem 并使用它,它与您在令牌中的信息基本相同。
public DisplayClaimCollection GetDisplayClaims(string username, string password)
{
WSTrustChannelFactory factory = null;
try
{
// use a UserName Trust Binding for username authentication
factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
"https://.../adfs/services/trust/13/usernamemixed");
factory.TrustVersion = TrustVersion.WSTrust13;
factory.Credentials.UserName.UserName = username;
factory.Credentials.UserName.Password = password;
var rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
AppliesTo = "Relying party endpoint address",
KeyType = KeyTypes.Symmetric,
RequestDisplayToken = true
};
IWSTrustChannelContract channel = factory.CreateChannel();
RequestSecurityTokenResponse rstr;
SecurityToken token = channel.Issue(rst, out rstr);
return rstr.RequestedDisplayToken.DisplayClaims;
}
finally
{
if (factory != null)
{
try
{
factory.Close();
}
catch (CommunicationObjectFaultedException)
{
factory.Abort();
}
}
}
}
但这不是正确的做法!您应该使用您的 RelyingParty 证书来解密加密的令牌并从中读取声明。