【发布时间】:2017-06-02 14:00:43
【问题描述】:
我刚刚完成了这一步(只需访问下面的 URL):
https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id={client_id}&response_type=code
这将我重定向到附加了代码查询字符串的重定向 URL:
https://example.com/?code=AwABAAAAvPM1KaPlrEqdFSBzjqfTGBCm.................................
在上述code 查询字符串的末尾,有一个额外的session_state 参数。
此问题顶部链接中概述的下一步是发出POST 请求,但我无法建立此呼叫。
以下是文档所代表的示例:
如何在 PHP 中形成和调用这个请求(不使用cURL)?
这是我的尝试,但我不知道我是否正确:
$url = 'https://login.microsoftonline.com/{tenant}/oath2/token';
$data = array( 'grant_type' => 'authorization_code',
'client_id' => '2d4d11a2-f814-46a7-890a-274a72a7309e',
'code' => 'AwABAAAAvPM1KaPlrEqdFSBzjqfTGBCm...................',
'redirect_uri' => 'https://example.com',
'resource' => 'https://graph.microsoft.com',
'client_secret' => '{client_secret}' );
$options = array(
'http' => array(
'header' => 'Content-type: application/x-www-form-urlencoded',
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$var_dump($result);
更新:上面的代码(执行时)返回一个500 Internal Server Error。
另外,我不知道是否应该将session_state(如上所述)添加到POST 调用中。
【问题讨论】:
标签: php azure post active-directory