gpt4 book ai didi

Azure Function App Binding ClaimsPrincial 不设置来自 JWT 的声明

转载 作者:行者123 更新时间:2023-12-02 07:22:55 25 4
gpt4 key购买 nike

我正在开发一个 SPA,它使用 Azure Function App 作为 API,使用 Azure Active Directory 进行身份验证。用户登录后,在本地存储中设置了 adal.access.token,但在绑定(bind)的 ClaimsPrincipal 参数中未正确设置声明,也未在 HttpRequest 中设置声明范围。无论是否设置了 Authorization: Bearer ... header ,声明主体对象看起来都相同。如何配置我的 Function App 以使用 AAD 和 ClaimsPrincipal 绑定(bind)?我使用 jwt.io 上的 token 调试器验证了声明是否已在访问 token 中设置。

public static MyFunction {
[FunctionName("MyFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "some-path")],
ClaimsPrincipal principal
){
// principal does not contain the claims, or any of the token info
}
}

然后我发送请求:

curl -X GET -H "Authorization: Bearer ..." http://localhost:7071/api/some-path

But the claims principle only has one claim, `http://schemas.microsoft.com/2017/07/functions/claims/authlevel: Admin`

更新:看起来主体变量在 Azure 中调用时已按预期设置,但在本地开发时未设置。

最佳答案

我假设您通过使用功能服务应用程序控制面板通过使用 Express 或其他方式激活 Azure AD 身份验证来创建应用程序注册。这样做会创建应用程序注册并将应用程序功能作为回复 URL,因此,如果您在开发环境中本地运行它并尝试登录,它永远不会将 token 发送到您的本地计算机,因为它不是源 URL。

基本上,您必须转到 azure 广告中的应用程序注册,转到身份验证并添加额外的回复/重定向网址,以指向应用程序的本地主机地址,无论是什么。 http://localhost:youriisexpressport有点东西。那么它也将在本地工作。

关于Azure Function App Binding ClaimsPrincial 不设置来自 JWT 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61808120/

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