【发布时间】:2018-02-09 02:44:32
【问题描述】:
我正在阅读此文档Authorize access to web applications using OAuth 2.0 and Azure Active Directory,并且已经到了成功登录时收到初始授权码的地步,但我很难获得授权令牌。据我了解,我需要在 POST 中发送代码以获取令牌。
我的 POST 请求是:
$code_received = $_GET['code']; //I get a code successfully
$url = 'https://login.microsoftonline.com';
$body="grant_type=authorization_code&client_id=myappid&code=" . $code_received . "&redirect_uri=https://mysite/auth.php&client_secret=***";
$options = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => $body
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
我得到的结果是 bool(false) .... 所以什么都没有返回——既不是令牌也不是错误。谁能看到我做错了什么?
【问题讨论】:
-
您是否希望自己解析 ADFS 响应?最近解决了很多问题,我求助于这个(github.com/onelogin/php-saml),它派上了用场。
标签: azure office365 azure-active-directory