【Azure 环境】使用Microsoft Graph PS SDK 登录到中国区Azure, 命令Connect-MgGraph -Environment China xxxxxxxxx 遇见登录错误

简介: 【Azure 环境】使用Microsoft Graph PS SDK 登录到中国区Azure, 命令Connect-MgGraph -Environment China xxxxxxxxx 遇见登录错误

问题描述

通过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

相关文章
|
2月前
|
API 开发工具 网络架构
【Azure Service Bus】使用Python SDK创建Service Bus Namespace资源(中国区)
本文介绍了如何使用Python SDK创建Azure Service Bus Namespace资源。首先,通过Microsoft Entra ID注册应用获取Client ID、Client Secret和Tenant ID,完成中国区Azure认证。接着,初始化ServiceBusManagementClient对象,并调用`begin_create_or_update`方法创建资源。
88 29
|
3月前
|
Java 开发工具 Spring
【Azure Application Insights】为Spring Boot应用集成Application Insight SDK
本文以Java Spring Boot项目为例,详细说明如何集成Azure Application Insights SDK以收集和展示日志。内容包括三步配置:1) 在`pom.xml`中添加依赖项`applicationinsights-runtime-attach`和`applicationinsights-core`;2) 在main函数中调用`ApplicationInsights.attach()`;3) 配置`applicationinsights.json`文件。同时提供问题排查建议及自定义日志方法示例,帮助用户顺利集成并使用Application Insights服务。
|
4月前
|
API 开发工具 Python
|
4月前
|
存储 XML 开发工具
【Azure Storage Account】利用App Service作为反向代理, 并使用.NET Storage Account SDK实现上传/下载操作
本文介绍了如何在Azure上使用App Service作为反向代理,以自定义域名访问Storage Account。主要内容包括: 1. **设置反向代理**:通过配置`applicationhost.xdt`和`web.config`文件,启用IIS代理功能并设置重写规则。 2. **验证访问**:测试原生URL和自定义域名的访问效果,确保两者均可正常访问Storage Account。 3. **.NET SDK连接**:使用共享访问签名(SAS URL)初始化BlobServiceClient对象,实现通过自定义域名访问存储服务。
|
5月前
|
API 开发工具 Python
【Azure Developer】编写Python SDK代码实现从China Azure中VM Disk中创建磁盘快照Snapshot
本文介绍如何使用Python SDK为中国区微软云(China Azure)中的虚拟机磁盘创建快照。通过Azure Python SDK的Snapshot Class,指定`location`和`creation_data`参数,使用`Copy`选项从现有磁盘创建快照。代码示例展示了如何配置Default Azure Credential,并设置特定于中国区Azure的`base_url`和`credential_scopes`。参考资料包括官方文档和相关API说明。
|
8月前
|
Java 开发工具 Windows
【Azure App Service】在App Service中调用Stroage SDK上传文件时遇见 System.OutOfMemoryException
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
|
9月前
|
JavaScript 前端开发 开发工具
【Azure Developer】使用JavaScript通过SDK进行monitor-query的client认证报错问题
AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.
|
10月前
|
Kubernetes API 开发工具
【Azure Developer】通过SDK(for python)获取Azure服务生命周期信息
需要通过Python SDK获取Azure服务的一些通知信息,如:K8S版本需要更新到指定的版本,Azure服务的维护通知,服务处于不健康状态时的通知,及相关的操作建议等内容。
105 18
|
10月前
|
调度
crash命令 —— ps
crash命令 —— ps
|
11月前
|
存储 Docker 容器
在Docker中,容器退出后,通过docker ps命令查看不到,数据会丢失么?
在Docker中,容器退出后,通过docker ps命令查看不到,数据会丢失么?