我正在尝试使用 Microsoft 帐户身份验证,但登录请求只返回“400 错误请求”。
参考:
- https://wiki.vg/Microsoft_Authentication_Scheme
- https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
任何帮助表示赞赏!
<?php
if(isset($_GET['code'])) {
$content = http_build_query(
array(
'client_id' => 'MY-CLIENT-ID',
'client_secret' => 'MY-SECRET',
'code' => $_GET['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => 'https://www.MY-DOMAIN.com/auth'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' =>
'Accept: application/json' . "\r\n" .
'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
'Content-Length: ' . strlen($content) . "\r\n",
'content' => $content
)
);
$context = stream_context_create($opts);
if (false !== ($tokenContents = @file_get_contents("https://login.live.com/oauth20_token.srf", false, $context)))
echo $tokenContents;
else
var_dump(error_get_last());
}
?>