【Azure 环境】使用Microsoft Graph PS SDK 登录到中国区Azure, 命令Connect-MgGraph -Environment China xxxxxxxxx 遇见登录错误
2024-09-28 12:25:54
问题描述
通过PowerShell 连接到Microsoft Graph 中国区Azure,一直出现AADSTS700016错误, 消息显示 the specific application was not installed in your tenant.
解决办法
根据弹出框中的错误提示, 这是因为MS Graph PowerShell并灭有注册到中国区Azure环境中,所以它无法找到Applicaiton ID: '14d82eec-204b-4c2f-b7e8-296a70dab67e'。
可以使用以下脚本进行验证:
Get-AzureADApplication -Filter "AppId eq '14d82eec-204b-4c2f-b7e8-296a70dab67e'"
为了解决这个问题,需要自己在Azure AD中主动注册一个Application,然后使用这个Application Id进行相应操作。需要执行的操作有:
1)登录到Azure AD 页面,注册一个App (Registered App: https://portal.azure.cn/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps)
2)赋予这个App相应的操作权限,如 User.Read.All, Group.ReadWrite.All 等
3)生成一个证书,并上传到App中
# 生成自签名证书
$Cert = New-SelfSignedCertificate -DnsName icy-ps-sdk-aad -CertStoreLocation "Cert:\CurrentUser\My" -FriendlyName "MicrosoftGraphSDK" -Subject "Test Cert for Microsoft Graph SDK"
4)在本地也安装同样的证书。
完成以上四步后,就可以使用以下的代码登录中国区Graph了。
#需要选择从本地选择证书,完成登录
Connect-MgGraph -Scopes "User.Read.All" -ClientId "你的appid=clientid" -Environment China -UseDeviceAuthentication # 直接登录方式
Connect-MgGraph -Environment China -AppId "你的App ID" -TenantId "你的Tenant ID" -CertificateThumbprint "证书指纹 Thumbprint" -Debug
附录: 完整的脚本
# 生成证书文件
$Cert = New-SelfSignedCertificate -DnsName icy-ps-sdk-aad -CertStoreLocation "Cert:\CurrentUser\My" -FriendlyName "MicrosoftGraphSDK" -Subject "Test Cert for Microsoft Graph SDK"
Get-ChildItem "Cert:\CurrentUser\My\$($Cert.thumbprint)"
Get-ChildItem "Cert:\CurrentUser\My\$($Cert.thumbprint)" | Export-Certificate -FilePath C:\temp\MicrosoftGraphSDK.cer #登录
Connect-MgGraph -Scopes "User.Read.All" -ClientId "your clientid" -Environment China -TenantId “your tenant id” -UseDeviceAuthentication Connect-MgGraph -Scopes "User.Read.All" -ClientId "your clientid" -Environment China -TenantId “your tenant id” -CertificateThumbprint "certificate thumbprint" #获取User
Get-MgUser get-mgcontext #退出登录
Disconnect-MgGraph
参考资料
Get started with the Microsoft Graph PowerShell SDK:https://docs.microsoft.com/en-us/powershell/microsoftgraph/get-started?view=graph-powershell-beta
最新文章
- Linux下Weblogic创建域方法和步骤
- Linux笔记:使用Vim编辑器
- 【PC网站前端架构探讨系列】关于中小型PC网站前端架构方案的讨论与实践
- Oracle Hints详解
- git使用--git命令项目提交问题总结
- 用while循环语句计算1!+2!+……20!之和
- easyUI之window
- Epic - Desirable Number
- HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
- jQuery Tags Input Plugin 插件的使用
- PP屏幕增强点
- centos6.5 安装git
- deeplearning.ai 卷积神经网络 Week 1 卷积神经网络 听课笔记
- UVA - 10723 类似LCS
- 网页提示错误(net::ERR_EMPTY_RESPONSE)
- hadoop配置项笔记 - hdfs
- 第四百零三节,python网站在线支付,支付宝接口集成与远程调试,
- TensorFlow安装教程---windows8.1
- maven中修改可用的版本
- compass Errno::EACCES on line [";897";] of C: Permission denied