账号有 azure 订阅的前往 https://shell.azure.com 登录即可,没有 azure 订阅的去下载个azure-cli。下载地址:https://docs.microsoft.com/en-us/cli/azure/install-azure-cli

登录

cmd 上输入

az login --allow-no-subscriptions

https://shell.azure.com 的可以跳过这步

创建 app

az ad app create --display-name office-api --end-date 2077-07-07 --password 1234s8yge4se5gh --required-resource-accesses "[{'resourceAccess': [{'id': '19dbc75e-c2e2-444c-a770-ec69d8559fc7','type': 'Role'},{'id': '741f803b-c850-494e-b5df-cde7c675a1ca','type': 'Role'}],'resourceAppId': '00000003-0000-0000-c000-000000000000'}]"

其中,

--display-name 是你的 app 显示名字,
--end-date 是 api 到期时间,格式 YYYY-MM-DD,
--password 是 client secret,这个要记住,
--required-resource-accesses 代表 api 权限,这里用了 Directory.ReadWrite.All 和 User.ReadWrite.All

输入之后稍等就会返回 api 信息,里面的 appId 就是 client id ,后面要用到,odata.metadata 里面包含了 tenant id
返回信息

给予 admin consent

az ad app permission admin-consent --id appId

用上面获得的 appId 替代 --id 内容,office api 即创建和授权成功。

Last modification:May 9th, 2021 at 07:20 pm
If you think my article is useful to you, please feel free to appreciate