/// <summary> /// 将微信返回的JSON属性映射到<see cref="ClaimsPrincipal"/> /// 默认值: /// ClaimTypes.Name : openid /// ClaimTypes.NameIdentifier : openid。 /// 这里假设我们已绑定开发者账号,微信返回的JSON含有unionid属性。 /// </summary> /// <param name="claimActions"></param> private void MapWeChatJsonKey(ClaimActionCollection claimActions) { claimActions.Clear(); claimActions.MapJsonKey(ClaimTypes.Name, "unionid"); claimActions.MapJsonKey(ClaimTypes.NameIdentifier, "unionid"); claimActions.MapJsonKey(WeChatClaimTypes.UnionId, "unionid"); claimActions.MapJsonKey(WeChatClaimTypes.OpenId, "openid"); }
/// <summary> /// Select a top level value from the json user data with the given key name and add it as a Claim. /// This no-ops if the key is not found or the value is empty. /// </summary> /// <param name="collection">The <see cref="ClaimActionCollection"/>.</param> /// <param name="claimType">The value to use for Claim.Type when creating a Claim.</param> /// <param name="jsonKey">The top level key to look for in the json user data.</param> public static void MapJsonKey(this ClaimActionCollection collection, string claimType, string jsonKey) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } collection.MapJsonKey(claimType, jsonKey, ClaimValueTypes.String); }
public static void MapAbpClaimTypes(this ClaimActionCollection claimActions) { if (AbpClaimTypes.UserName != "name") { claimActions.MapJsonKey(AbpClaimTypes.UserName, "name"); claimActions.DeleteClaim("name"); claimActions.RemoveDuplicate(AbpClaimTypes.UserName); } if (AbpClaimTypes.Email != "email") { claimActions.MapJsonKey(AbpClaimTypes.Email, "email"); claimActions.DeleteClaim("email"); claimActions.RemoveDuplicate(AbpClaimTypes.Email); } if (AbpClaimTypes.EmailVerified != "email_verified") { claimActions.MapJsonKey(AbpClaimTypes.EmailVerified, "email_verified"); } if (AbpClaimTypes.PhoneNumber != "phone_number") { claimActions.MapJsonKey(AbpClaimTypes.PhoneNumber, "phone_number"); } if (AbpClaimTypes.PhoneNumberVerified != "phone_number_verified") { claimActions.MapJsonKey(AbpClaimTypes.PhoneNumberVerified, "phone_number_verified"); } if (AbpClaimTypes.Role != "role") { claimActions.MapJsonKeyMultiple(AbpClaimTypes.Role, "role"); } claimActions.RemoveDuplicate(AbpClaimTypes.Name); }
/// <summary> /// Select a top level value from the json user data with the given key name and add it as a Claim. /// This no-ops if the key is not found or the value is empty. /// </summary> /// <param name="collection"></param> /// <param name="claimType">The value to use for Claim.Type when creating a Claim.</param> /// <param name="jsonKey">The top level key to look for in the json user data.</param> public static void MapJsonKey(this ClaimActionCollection collection, string claimType, string jsonKey) { collection.MapJsonKey(claimType, jsonKey, ClaimValueTypes.String); }
public static void MapBattleNetClaims(this ClaimActionCollection collection) { collection.MapJsonKey(JwtClaimTypes.Subject, JwtClaimTypes.Subject); collection.MapJsonKey(ExternalClaimTypes.BattleNet.Name, "battletag"); }
public static void MapDiscordClaims(this ClaimActionCollection collection) { collection.MapJsonKey(JwtClaimTypes.Subject, "id"); collection.MapJsonKey(ExternalClaimTypes.Discord.Name, "username"); collection.MapJsonKey(ExternalClaimTypes.Discord.Discriminator, "discriminator"); }