【问题标题】:Office 365 Authentication: Use the authorization code to request an access tokenOffice 365 身份验证:使用授权代码请求访问令牌
【发布时间】: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


【解决方案1】:

您至少在$body 中没有指定resource。这应该是您尝试使用的 API 的资源 URI。它告诉 Azure AD 你想调用什么 API。

对于 https://graph.microsoft.com 的 Microsoft Graph API。

对于 Azure AD Graph API,它是 https://graph.windows.net

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 2020-02-12
    • 1970-01-01
    • 2018-08-27
    • 2020-01-15
    • 2017-11-22
    相关资源
    最近更新 更多