gpt4 book ai didi

c# - 身份服务器 4 : How so you include additional claims and get the value in an API controller?

转载 作者:太空宇宙 更新时间:2023-11-03 12:26:46 25 4
gpt4 key购买 nike

最佳答案

当您定义一个 api 资源(查看 Config.cs)时,您可以这样做:

new ApiResource
{
Name = "api",
DisplayName = "My API",

UserClaims =
{
JwtClaimTypes.Id,
JwtClaimTypes.Subject,
JwtClaimTypes.Email
}
}

它定义您的 API 将接收这些声明。

编辑:

最好将关联资源添加到 GetIdentityResources 函数(请参阅 Config.cs)

浏览一下官方文档以获得更好的图片 http://docs.identityserver.io/en/release/topics/resources.html .

我给你一个来自个人项目的完整例子:

    public static IEnumerable<IdentityResource> GetIdentityResources()
{
//>Declaration
var lIdentityResources = new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email()
};

//>Processing
foreach (var lAPIResource in GetApiResources())
{
lIdentityResources.Add(new IdentityResource(lAPIResource.Name,
lAPIResource.UserClaims));
}

//>Return
return lIdentityResources;
}

public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource
{
Name = "api1",
DisplayName = "api1 API",

UserClaims =
{
JwtClaimTypes.Id,
JwtClaimTypes.Subject,
JwtClaimTypes.Email
}
}
};
}

关于c# - 身份服务器 4 : How so you include additional claims and get the value in an API controller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44537222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com