Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Identity Server中为用户提供更新其自身信息的选项_C#_Api_Oauth 2.0_Identityserver4_Openid Connect - Fatal编程技术网

C# 如何在Identity Server中为用户提供更新其自身信息的选项

C# 如何在Identity Server中为用户提供更新其自身信息的选项,c#,api,oauth-2.0,identityserver4,openid-connect,C#,Api,Oauth 2.0,Identityserver4,Openid Connect,我已将用户身份派生为 public class MyAppUser : IdentityUser { public MyAppUser () : base() { } public MyAppUser (string userName) : base(userName) { } public string FirstName { get; set; } public string LastName { get; se

我已将用户身份派生为

    public class MyAppUser : IdentityUser
    {
        public MyAppUser () : base() { }
        public MyAppUser (string userName) : base(userName) { }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string CurrentAddress { get; set; }
    }
我已经在声明中添加了所有这些属性值,以便我们可以将这些值发送给用户以查看详细信息

await UsersRepository.AddClaimAsync(appuser, new Claim("firstName", "MyName"));
await UsersRepository.AddClaimAsync(appuser, new Claim("lastName", "MyLastName"));
await UsersRepository.AddClaimAsync(appuser, new Claim("currentAddress", "MyAddress"));
我这里有两个问题

第1期:-值在两个位置重复

  • 与MyAppUser
  • 与索赔
问题:-这是正确的方法吗?如果没有,最好的实施方法是什么

第2期:-我想让用户选择更新自己的信息,如CurrentAddress或FirstName或 姓

问题:-


解决上述问题的一种方法是向所有用户提供AdminAPI端点访问权限。但这是正确的方法吗?在IdentityServer中实现此功能的最佳方法是什么。

因为您使用的是IdentityServer 4,所以我将通过定义标识资源来创建“概要文件”范围

公共静态IEnumerable GetIdentityResources()
{
返回新列表
{
新身份资源(
名称:“个人资料”,
userClaims:new[]{“name”,“email”,“website”},
displayName:“您的个人资料数据”)
};
}
从这里,您可以看到如何实现
IProfileService
接口,以便访问管理用户配置文件信息的单独数据库或API

配置文件服务文档:


您可以设置一个单独的用户配置文件或用户信息服务,您的用户可以在其中更新其信息。这样,他们就不会直接修改实际身份验证服务范围内的数据。您可以从身份验证令牌中删除不必要的声明,并仅将其作为“配置文件”范围的一部分提供。这将减少你提到的多余的索赔。这样做还可以让您有更多的空间添加您可能需要的任何用户配置文件信息(电话号码、电子邮件等)。

用户配置文件或用户信息服务->此服务将位于Identity service Admin API?@DJ根据您的特定应用程序/用例,您可以通过多种方式实现它。您确实可以通过添加自己的控制器和端点来扩展identity server API。我不知道您的总体架构是如何布置的,所以我不能推荐一种具体的方法。我想您有单独的应用程序或API,您正在使用ID4进行保护?如果是这样,您可以在那里添加使其与主身份验证服务器分离的功能。取决于什么对您的用例最有意义。最简单的方法可能只是扩展identity server API。