Loading... 原帖:https://hostloc.com/thread-853850-1-2.html ====================================================================== 参考教程 ======== 【更新】azure cli 一键生成 office api 给予所有权限 https://hostloc.com/thread-840509-1-1.html ### 使用 azure cli 注册应用、添加权限和密钥使用 azure cli 注册应用、添加权限和密钥 #### 1、下载和安装 azure cli 网址:https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli 直链:https://azcliprod.blob.core.windows.net/msi/azure-cli-2.24.2.msi 下载之后运行文件安装 azure cli #### 2、下载和解压配置文件 manifest.json 例如解压到 Z:\AzCli\manifest.json ![](https://mjj.link/usr/uploads/2021/06/249700354.png) #### 3、打开 cmd 命令行窗口,输入命令 ```bash Z: cd Z:\AzCli az login --allow-no-subscriptions ``` 在打开的浏览器中输入用户名和密码登录 ![](https://mjj.link/usr/uploads/2021/06/1578447369.png) 登录成功之后,命令行窗口显示租户相关信息 记录 租户ID: bf7757a1-b331-................. "tenantId": "bf7757a1-b331-................." ```bash [ { "cloudName": "AzureCloud", "id": "bf7757a1-b331-.................", "isDefault": true, "name": "N/A(tenant level account)", "state": "Enabled", "tenantId": "bf7757a1-b331-.................", "user": { "name": "admin@tenant.onmicrosoft.com", "type": "user" } } ] ``` #### 4、注册应用 ```bash az ad app create --display-name Application --end-date 2099-12-31 --password App1icati0nPa55word --required-resource-accesses @manifest.json ``` 其中的选项按需修改 --display-name Application --end-date 2099-12-31 --password App1icati0nPa55word 注册成功之后,命令行窗口显示应用相关信息 记录应用程序(客户端) ID: 3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx "appId": "3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx", 客户端密码为 App1icati0nPa55word ```bash { "appId": "3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx", "displayName": "Application", "passwordCredentials": [ { "additionalProperties": null, "customKeyIdentifier": null, "endDate": "2099-12-31T00:00:00+00:00", "keyId": "65466be7-0f12-4f32-8e39-3a22cbe081e7", "startDate": "2021-06-05T11:26:52.333549+00:00", "value": null }], "requiredResourceAccess": [ { "additionalProperties": null, "resourceAccess": [ { "additionalProperties": null, "id": "7dd1be58-6e76-4401-bf8d-31d1e8180d5b", "type": "Role" }, }] } ``` ![](https://mjj.link/usr/uploads/2021/06/2605748377.png) #### 5、为应用程序授权 上一步生成的应用程序(客户端) ID: 3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx --id appId 3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx ```bash az ad app permission admin-consent --id appId 3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx ``` ![](https://mjj.link/usr/uploads/2021/06/1516090420.png) #### 6、使用应用程序所需的信息如下 租户ID: bf7757a1-b331-................. 应用程序客户端 ID: 3eb1d9a8-a9a2-4f18-xxxx-xxxxxxxxxxxx 应用程序客户端密码:App1icati0nPa55word Last modification:June 24, 2021 © Allow specification reprint Like 如果觉得我的文章对你有用,请随意赞赏