Powershell Connect-MsolService无法使用Microsoft Graph访问令牌进行身份验证

问题描述:

我正在尝试使用  Connect-MsolService对MSOnline powershell模块进行身份验证。我使用Azure AD Graph(graph.windows.net)通过Web应用程序获取用户的访问令牌。如果我使用该令牌进行身份验证( Connect-MsolService
-AccessToken< token>
),一切正常。

I am trying to authenticate with the MSOnline powershell module using Connect-MsolService. I obtain a user's access token via a web application using the Azure AD Graph (graph.windows.net). If I authenticate with that token (Connect-MsolService -AccessToken <token>), things work fine.

但是,因为建议使用使用较新的Microsoft Graph(graph.microsoft.com)我想切换到它,但Connect-MsolService失败并带有它授予的令牌。如果我运行  Connect-MsolService -MsGraphAccessToken< token>
我收到以下错误: 

However, since it's recommended to use the newer Microsoft Graph (graph.microsoft.com) I want to switch over to it, but the Connect-MsolService fails with the token granted by it. If I run Connect-MsolService -MsGraphAccessToken <token>, I get the following error: 

Connect-MsolService : The given key was not present in the dictionary.

要获取访问令牌,我将用户发送到https://login.windows.net/common / oauth2 /授权使用正确的客户端ID,redirect_uri和资源设置为  https://graph.microsoft.com的终点。验证成功,我收到有效的
令牌(例如,对https://graph.microsoft.com/v1.0/me的请求正常工作)。 

To obtain the access token, I send users to the https://login.windows.net/common/oauth2/authorize end point with the correct client id, redirect_uri and resource set to https://graph.microsoft.com. The authentication succeeds and I get a valid token back (for example, a request to https://graph.microsoft.com/v1.0/me works fine). 

我在这里做错了什么?

感谢您的帮助!

最好,

史蒂文

Best,
Steven





To正确排除故障我们需要fiddler跟踪和应用程序详细信息。我们还需要敏感信息,例如您的订阅和租户详细信息,这超出了论坛支持的范围。

To troubleshoot this properly we would need the fiddler trace and the application details. We would also need sensitive information like your Subscription and Tenant details, which is beyond the purview of the Forums Support.


我们建议你打开一个  技术支持票 
我们的工程师仔细查看问题并为您提供适当的帮助。

We would suggest you to open a Technical Support ticket for our engineers to have a closer look at the issue and assist you appropriately.


确保安装了最新的Azure AD powershell模块。

Make sure that you have the latest Azure AD powershell module installed as well.