gpt4 book ai didi

azure - Azure AD JWT token 中缺少应用程序权限范围

转载 作者:行者123 更新时间:2023-12-02 23:30:35 27 4
gpt4 key购买 nike

我们的应用程序正在管理 Office 365 日历,无需使用 Office 365 Exchange Online API 的用户明确同意。对于客户的现有安装,这按预期工作,但对于新客户,对 Exchange Online API 的所有请求都会返回 401 Unauthorized回复。我们已将范围缩小到 JWT token 中缺少的角色声明。

我们的问题是,JWT 中缺少此角色声明是否是一个错误,或者这是设计使然。也许 Azure AD 团队的某个人可以分享他们的想法。

如何重现

在 Azure AD 中,我们创建了应用注册。已上传公钥以便通过 ADAL4j 进行身份验证。除此之外,一些应用程序权限已授予 Exchange Online:

application permissions

我们可以使用 https://outlook.office365.com/ 通过 ADAL4j 成功请求访问 token 作为资源 ID。 JWT 看起来像这样(删除了一些不相关的信息):

{
typ: "JWT",
alg: "RS256",
},
{
aud: "https://outlook.office365.com/",
iss: "https://sts.windows.net/yyy/",
app_displayname: "Test",
appid: "app-id",
ver: "1.0"
}

可以看出,属性 roles JWT token 中缺失。

调用 Exchange Online API(例如 https://outlook.office365.com/api/v2.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681d1b0d1a281c0d0609061c46070605010b1a071b070e1c460b0705" rel="noreferrer noopener nofollow">[email protected]</a>/calendars )时,将 JWT 作为承载 token 发送,即 401 Unauthorized被返回。 x-ms-diagnostics标题提到:

2000008;reason="The token contains no permissions, or permissions can not be understood.";error_category="invalid_grant"

预期行为

当使用旧的应用程序注册(使用 Azure 经典门户创建,如果我没记错的话)时,JWT 确实包含 Roles具有我们请求的角色的属性:

{
typ: "JWT",
alg: "RS256",
},
{
aud: "https://outlook.office365.com/",
iss: "https://sts.windows.net/yyy/",
app_displayname: "Test",
appid: "app-id",
roles: [
"Calendars.ReadWrite.All"
],
ver: "1.0"
}

在调用 Exchange Online API 时,使用此 JWT 作为承载 token 可以按预期工作。

解决方法

我们已通过使用新应用注册的“授予权限”按钮解决了该问题:

grant permissions button

现在,Calendars.ReadWrite.All角色存在于 JWT 中,因此一切都按预期进行。

问题

过去我们从来不需要执行“授予权限”操作。另外,this page提及(添加强调):

As an administrator, you can also consent to an application's delegated permissions on behalf of all the users in your tenant. Administrative consent prevents the consent dialog from appearing for every user in the tenant, and can be done in the Azure portal by users with the administrator role. From the Settings page for your application, click Required Permissions and click on the Grant Permissions button

但是,“在所有邮箱中读取和写入日历”权限是应用程序权限,而不是委派权限,如 this page 中所述。 .

该解决方法是否是我们缺少角色声明问题的正确解决方案,还是 Azure AD 方面存在其他问题?

最佳答案

解决方法是正确的解决方案。当您的应用程序需要应用程序权限时,管理员必须通过单击“授予权限”按钮(如您所做的那样)或将 admin_consent 传递到登录 URL 来同意。这适用于 AAD v1 应用程序模型。对于 AAD v2 应用程序模型,有一种不同的方式来获得管理员同意。更多信息here .

过去(Azure 经典门户),当您向应用程序添加应用程序权限时,会自动授予同意。新的 Azure 门户中的情况并非如此。

关于azure - Azure AD JWT token 中缺少应用程序权限范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50235361/

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