Microsoft Graph REST API无效的客户端密钥

Wow*_*Bow 4 curl azure office365api azure-ad-graph-api microsoft-graph

我需要进行以下POST调用.但是,即使我提供了正确的客户端ID和密码ID,我的电话也会被拒绝.

    curl POST https://login.microsoftonline.com/f02....e3/oauth2/token
 -H 'Content-Type: application/x-www-form-urlencoded'  --data 'grant_type=authorization_code&redirect_uri=https://requestb.in/ac&
source=https://graph.microsoft.com&client_id=1e1....-913d9
&client_secret=YmbSFYz.....4Uk=&scope=mail.read&code=AaAAA........on0a569'
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误:

    curl: (6) Could not resolve host: POST
    {"error":"invalid_client","error_description":"AADSTS70002: 
Error validating credentials. AADSTS50012: Invalid client secret is
 provided.\r\nTrace ID: 78d...a2b\r\nCorrelation ID: 
01....ab2\r\nTimestamp: 2016-12-14 01:46:47Z","error_codes":[70002,50012],"timestamp":"2016-12-14 01:46:47Z","trace_id":"78d....a2b","correlation_id":"018.....ab2"}
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题?

编辑:我正在尝试在本文档中实现第二部分(即获取令牌)

Gar*_*SFT 5

您提供的帖子是利用AAD V2端点.但根据您的代码段,您使用的是V1端点https://login.microsoftonline.com/f02....e3/oauth2/token.要通过V1端点获取访问令牌,可以参考https://graph.microsoft.io/en-us/docs/authorization/app_authorization了解更多详细信息.

对于V2授权端点,您可以检查您正在使用的端点:

GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?...

POST https://login.microsoftonline.com/common/oauth2/v2.0/token

此外,它还需要一个v2.0广告应用程序:

本文假设v2.0注册,因此您将在应用程序注册门户上注册您的应用程序.


Mut*_*nth 5

这是由于client_secret。它可能包含特殊字符。

encodeURIComponent()函数对URI组件进行编码。此功能编码特殊字符。此外,它还对以下字符进行编码:,/?:@&= + $#

使用以下之一:

encodeURIComponent(client_secret);
Run Code Online (Sandbox Code Playgroud)