Asp.net core 使用Identity server在Azure功能中获取用户信息和其他声明
我有一个应用程序,其中身份验证是使用IdentityServer4和Azure AD作为OpenID提供者完成的。IdentityServer4托管在Azure应用程序服务中。在成功的身份验证之后,我能够在Angular应用程序中获得访问令牌。访问令牌被传递到基于.Net内核的RESTful API,该API托管在Azure Function 3.x中。 在我的Azure函数中,我希望在不触及IdentityServer4的端点“/connect/userinfo”的情况下获取用户信息和其他声明 类似于以下内容的内容将有助于获得索赔Asp.net core 使用Identity server在Azure功能中获取用户信息和其他声明,asp.net-core,authentication,azure-functions,identityserver4,claims,Asp.net Core,Authentication,Azure Functions,Identityserver4,Claims,我有一个应用程序,其中身份验证是使用IdentityServer4和Azure AD作为OpenID提供者完成的。IdentityServer4托管在Azure应用程序服务中。在成功的身份验证之后,我能够在Angular应用程序中获得访问令牌。访问令牌被传递到基于.Net内核的RESTful API,该API托管在Azure Function 3.x中。 在我的Azure函数中,我希望在不触及IdentityServer4的端点“/connect/userinfo”的情况下获取用户信息和其他声明
[FunctionName("MyFunctionName")]
public static HttpResponseMessage Run(
[HttpTrigger(
AuthorizationLevel.Anonymous,
"get", "post",
Route = "MyFunctionName")]HttpRequestMessage req,
ILogger log,
ClaimsPrincipal claimsPrincipal)
{
// My function code here...
}
如何在Azure函数中获取I用户信息和其他声明,其中身份验证由IdentityServer4完成,Azure AD作为OpenID提供程序如果您拥有有效的访问令牌,则您可以自行向UserInfo端点发出请求,以检索剩余的用户详细信息 阅读更多关于它的信息
如果您不想访问userinfo端点,唯一的选择是直接在令牌中包含所需的数据。在这里,您需要在令牌大小和便利性之间进行权衡。然后你会得到一个真正的无状态系统。如果你不想点击Identity Server的用户信息端点来获取用户信息和其他声明,下面是需要做的事情
public static IEnumerable<ApiResource> GetApis()
{
var apiResourceList = new List<ApiResource>
{
new ApiResource(IdentityServerConstants.LocalApi.ScopeName)
{
UserClaims =
{
JwtClaimTypes.Email,
JwtClaimTypes.PhoneNumber,
JwtClaimTypes.GivenName,
JwtClaimTypes.FamilyName,
JwtClaimTypes.PreferredUserName
},
}
};
return apiResourceList;
}
公共静态IEnumerable
这也非常有用。我想在Azure功能中访问此信息。为每个Http请求点击/userinfo端点不是一个好主意。应该有某种机制,通过它我可以访问userinfo而不必到达终点。更新了我的答案