C# 为什么要使用;索赔类型。参与者“;return";阿克特;?
我有以下资料:C# 为什么要使用;索赔类型。参与者“;return";阿克特;?,c#,C#,我有以下资料: /* create claims */ const string actorClaimValue = "actor"; SecurityToken sendToken = new JwtSecurityToken( claims: new List<Claim> { new Claim( type: ClaimTypes.Actor, value: actorClaimValue
/* create claims */
const string actorClaimValue = "actor";
SecurityToken sendToken = new JwtSecurityToken(
claims: new List<Claim> {
new Claim(
type: ClaimTypes.Actor,
value: actorClaimValue
),
}
);
JwtSecurityTokenHandler sendHandler = new JwtSecurityTokenHandler();
string sendTokenString = sendHandler.WriteToken( sendToken );
Console.Out.WriteLine( sendTokenString );
// eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhY3RvcnQiOiJhY3RvciJ9.
/* get claims */
JwtSecurityTokenHandler receiveHandler = new JwtSecurityTokenHandler();
JwtSecurityToken token = (JwtSecurityToken)receiveHandler.ReadToken( sendTokenString );
Claim actorClaim = token.Claims.FirstOrDefault( c => c.Type == ClaimTypes.Actor );
Console.Out.WriteLine( actorClaim == null );
// True
foreach( Claim claim in token.Claims ) {
Console.Out.WriteLine( "{0}: {1}", claim.Type, claim.Value );
// actort: actor
}
导致索赔类型为“actort”
编辑:
我只是尝试了ClaimTypes.Role
而不是ClaimTypes.Actor
,它很有效。。。可能的错误?发现的错误与包含的错误相反
因为我使用的是JwtSecurityToken
s,所以在过滤claim-actorClaim=token.Claims.FirstOrDefault(c=>c.type==ClaimTypes.Actor)之前,我应该使用映射找出我得到的索赔类型值代码>
public const string Actor = "http://schemas.xmlsoap.org/ws/2009/09/identity/claims/actor"