为什么 "Application permissions" 在 Azure AD 的 "Request API permissions" 中被禁用?

Why is "Application permissions" disabled in Azure AD's "Request API permissions"?

我正在尝试授予控制台应用程序在 Azure AD 中调用 API 的权限。

当我去"Add permissions,"时"application permissions"是灰色的,我只能select"delegated permissions."

我的理解是应用程序权限适用于控制台应用程序,因为它在后端运行并且用户不会登录。

来自 "application permissions" 的帮助文本:

Your application runs as a background service or daemon without a signed-in user.

"delegated permissions" 的帮助文本:

Your application needs to access the API as the signed-in user.

为什么 "application permissions" 被禁用?

据我了解,您公开了受 Azure AD 保护的自定义 api。如果是这样,您需要 define the application permission 编辑 api 应用程序的清单。

清单:

"appRoles": [
        {
            "allowedMemberTypes": [
                "Application"
            ],
            "description": "Apps that have this role have the ability to invoke my API",
            "displayName": "Can invoke my API",
            "id": "fc803414-3c61-4ebc-a5e5-cd1675c14bbb",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "myTestRole"
        }
    ]

然后会显示申请权限。

您实际上并没有以这种方式授予它权限。这真的很混乱。相反,您将注册的应用程序添加到您的订阅并应用 reader 角色,有点像通过 IAM。看这里:

https://medium.com/@crlmas07/programmatic-access-to-azure-portal-d925ea90831e