/// <summary> /// 转换为Identity资源数组 /// </summary> /// <param name="identityResources">Identity资源信息数组</param> /// <returns>Identity资源数组</returns> public static IdentityResource[] ToIdentityResources(this IdentityResourceInfo[] identityResources) { if (identityResources.IsNullOrLength0()) { return(null); } var result = new IdentityResource[identityResources.Length]; for (var i = 0; i < result.Length; i++) { var source = identityResources[i]; var type = source.Type != null?source.Type.ToLower() : null; if ("openid".Equals(type)) { result[i] = new IdentityResources.OpenId(); } else if ("profile".Equals(type)) { result[i] = new IdentityResources.Profile(); } else if ("address".Equals(type)) { result[i] = new IdentityResources.Address(); } else if ("email".Equals(type)) { result[i] = new IdentityResources.Email(); } else if ("phone".Equals(type)) { result[i] = new IdentityResources.Phone(); } else { result[i] = new IdentityResource(source.Name, source.DisplayName, source.UserClaims); } result[i].Description = source.Description; result[i].Enabled = source.Enabled; result[i].Emphasize = source.Emphasize; result[i].Required = source.Required; result[i].ShowInDiscoveryDocument = source.ShowInDiscoveryDocument; } return(result); }
public ResourceStore() { apiResources["https://example.com/api"] = new ApiResource("https://example.com/api") { UserClaims = { JwtClaimTypes.Email }, Scopes = { new Scope { Name = "read:product", DisplayName = "Read access to product data" } } }; identityResources["openid"] = new IdentityResources.OpenId(); identityResources["email"] = new IdentityResources.Email(); identityResources["address"] = new IdentityResources.Address(); identityResources["phone"] = new IdentityResources.Phone(); identityResources["profile"] = new IdentityResources.Profile(); }