使用AZ CLI创建Azure应用程序注册的问题

4
我正在尝试创建一个具有访问Windows Azure AD权限的Azure AD应用程序,并更新清单。我已经成功创建/配置了一个新的应用注册,但在尝试配置清单时遇到了问题。
我尝试使用微软提供的示例代码(https://learn.microsoft.com/en-us/cli/azure/ad/app?view=azure-cli-latest#az-ad-app-create),并将现有应用注册中的“resourceAppId”更新为该代码,但是Bash报错。
az ad app create --display-name myTest --homepage https://blah.test.com --reply-urls https://blah.test.com/.auth/login/add/callback --required-resource-accesses @manifest.json("manifest.json" contains the following content)

[{"resourceAppId": "00000002-0000-0000-c000-000000000000",
"resourceAccess": [
                    {
                     "id": "a42657d6-7f20-40e3-b6f0-cee03008a62a-test",
                     "type": "Scope"
                    }
                  ]
}]

我复制了示例代码并更新了一些参数,所以我期望它可以运行。感谢您提供任何建议。

当我通过门户运行时,我收到了以下错误:

图片描述在此输入


我看到你的 "id" 后面有一个 -test,它跟着一个 GUID a42657d6-7f20-40e3-b6f0-cee03008a62a-test。尝试将其替换为一个新的有效 GUID。 - Rohit Saigal
我只是为了测试而将其存根。我正在使用从现有应用程序注册清单中复制的 GUID(已正确设置)。 - tothecl0ud
好的,明白了。你能提供一下你收到的错误信息的更多细节吗? - Rohit Saigal
你能提供错误信息吗? - Joy Wang
1个回答

5

由于您提供的有用信息过少,我不确定您遇到了什么错误。

我测试了您的脚本,得到了以下错误。

az ad app create --display-name 'myTest' --homepage 'https://blah.test.com --reply-urls https://blah.test.com/.auth/login/add/callback' --required-resource-accesses 'C:\Users\joyw\Desktop\manifest.json'
az : ERROR: '--identifier-uris' is required for creating an application
    At line:1 char:1
    + az ad app create --display-name 'myTest' --homepage 'https://blah.tes ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (ERROR: '--ident... an application:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError

如果您也遇到这个错误,请添加参数--identifier-uris 'https://mytestapp.websites.net',完整的命令应该像这样:
az ad app create --display-name 'myTest' --homepage 'https://blah.test.com' --reply-urls 'https://blah.test.com/.auth/login/add/callback' --identifier-uris 'https://mytestapp.websites.net' --required-resource-accesses 'C:\Users\joyw\Desktop\manifest.json'

那么它将正常工作。

输入图像描述


据我了解,您可能认为在manifest.json中的resourceAppId有误。 如果您没有收到上述错误,则可以按照下面的信息进行故障排除,并确保您在manifest.json中使用了正确的属性。

我的manifest.json文件:

   [{
      "resourceAppId": "69ae001f-xxxxxxxx-375585ac983e",
      "resourceAccess": [
        {
          "id": "6833b2c6-9954-43e1-ac46-f54a26a3b693",
          "type": "Scope"
        },
        {
          "id": "1b4f816e-5eaf-48b9-8613-7923830595ad",
          "type": "Role"
        }
      ]
    }]
resourceAppId 是服务主体的应用程序 ID(即 AD 应用程序的应用程序 ID),所以您是正确的。
resourceAccess 中,typeScopeRoleScope 表示 委派权限Role 表示 应用程序权限。 对于 应用程序权限,您可以在正在使用的 AD 应用程序的清单文件中的 appRoles 中找到它(对于我的示例,是应用程序 69ae001f-xxxxxxxx-375585ac983e)。 对于 委派权限,您可以在清单中的 oauth2Permissions 中找到它。 然后获取相应位置的 id
请检查我的示例 AD 应用程序的清单,并注意 id 和对应关系,这将变得清晰明了。 appRoles:
"appRoles": [
    {
      "allowedMemberTypes": [
        "Application"
      ],
      "displayName": "SurveyCreator",
      "id": "1b4f816e-5eaf-48b9-8613-7923830595ad",
      "isEnabled": true,
      "description": "Creators can create Surveys",
      "value": "SurveyCreator"
    }
  ]

oauth2Permissions:

 "oauth2Permissions": [
    {
      "adminConsentDescription": "Allow the application to access joywebtest on behalf of the signed-in user.",
      "adminConsentDisplayName": "Access joywebtest",
      "id": "6833b2c6-9954-43e1-ac46-f54a26a3b693",
      "isEnabled": true,
      "type": "User",
      "userConsentDescription": "Allow the application to access joywebtest on your behalf.",
      "userConsentDisplayName": "Access joywebtest",
      "value": "user_impersonation"
    }
  ]

最后,我们可以在门户中检查刚刚创建的AD应用程序。它将具有我们设置的所需权限

输入图像说明

如需更多详细信息,您还可以参见Azure Active Directory应用程序清单


我认为将JSON拆分到单独的文件中是个好办法。 - tothecl0ud

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接