在 Azure Active Directory 应用程序注册中,如何以编程方式公开 API (user_impersonation)?

问题描述 投票:0回答:1

我正在更新一个 Powershell 脚本,该脚本创建并配置多个应用程序注册以构建 IAM 解决方案。由于项目优先级发生了变化,该脚本已有大约 18 个月没有执行。它混合使用对 Azure CLI 和 Microsoft Graph 界面的调用来创建多个应用程序注册。

每个应用程序注册所涉及的步骤大致相似:

  • 为应用程序定义一组所需的资源访问权限(范围和角色访问权限的组合)
  • 创建应用程序注册
  • 创建服务主体
  • 迭代资源访问并将其作为权限添加到应用程序中

我必须进行一些小更新才能使脚本成功运行(将对

ObjectId
的引用替换为对
Id
的引用,删除在创建应用程序时使用密码等。 )

脚本现在运行没有错误,但我的问题是行为与以前不一样。

以前,对于每个应用程序注册,都会公开一个具有范围的 API

user_impersonation

这在清单中反映为一组

oauth2Permissions

但是,当我运行修改后的脚本时,没有暴露 API,也没有设置

oauth2Permissions

我的问题是:如何设置 oauth2Permissions 并以 user_impersonation 范围**以编程方式**公开 API,而不是通过管理控制台。

(我已经搜索了 Microsoft 文档以获取有关设置 OAuth2Permissions 的详细信息,但只找到了操作 OAuth2PermissionGrant 的详细信息,这不是同一件事。)

azure-active-directory microsoft-graph-api azure-cli
1个回答
0
投票

要设置应用程序 ID URI,请使用以下 PowerShell 脚本:

Connect-MgGraph -Scopes "Application.ReadWrite.All"

$params = @{
    identifierUris = @(
        "https://b2caadtenant.onmicrosoft.com/AppID"
    )
}
Update-MgApplication -ApplicationId AppObjID -BodyParameter $params

enter image description here

在门户中,应用程序 ID URI 已更新:

enter image description here

要创建范围,使用以下脚本:

$api = @{
    oauth2PermissionScopes = @(
        @{
        AdminConsentDescription = "user_impersonation"
        AdminConsentDisplayName = "user_impersonation"
        Type = "Admin"
        Value = "user_impersonation"
        Id = $([guid]::NewGuid())
    }
    )
}
Update-MgApplication -ApplicationId AppObjID -Api $api

enter image description here

范围创建成功:

enter image description here

现在,您可以获取使用以下 Microsoft Query 创建的范围

https://graph.microsoft.com/v1.0/servicePrincipals/SPObjID/oauth2PermissionScopes

enter image description here

输出:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('xxx')/oauth2PermissionScopes",
"value": [
{
"adminConsentDescription": "user_impersonation",
"adminConsentDisplayName": "user_impersonation",
"id": "786912f0-1cd0-496b-b619-XXX",
"isEnabled": true,
"type": "Admin",
"userConsentDescription": null,
"userConsentDisplayName": null,
"value": "user_impersonation"
}
]
}

要在 API 权限刀片中将上述范围分配为权限,请使用以下脚本:

$params = @{ requiredResourceAccess = @( @{ resourceAppId = "ClientID" resourceAccess = @( @{ id = "IDfromthe ABove" type = "Scope" } ) } ) } Update-MgApplication -ApplicationId 6646189d-84ef-4f40-9d26-895654ad01b4 -BodyParameter $params

enter image description here

enter image description here

参考:

azure - AADB2C90205:获取刷新令牌时面临权限不足 - Stack Overflow by me

© www.soinside.com 2019 - 2024. All rights reserved.