简体   繁体   English

PHP Microsoft Azure oauth2令牌POST方法不起作用

[英]PHP Microsoft Azure oauth2 token POST method not working

This is driving me nuts! 这真让我发疯!

If the method is POST, why Azure is returning an "AADSTS90056: This endpoint only accepts POST, OPTIONS requests. Received a GET request" error? 如果方法是POST,为什么Azure返回“ AADSTS90056:此终结点仅接受POST,OPTIONS请求。收到GET请求”错误?

Code: 码:

$url='http://login.microsoftonline.com/common/oauth2/v2.0/token';
 $data = array('code'=>$code,'resource'=>$resource,'redirect_uri' => $redirect_uri, 'client_id' => $client_ID, 'scope' => $scope, 'grant_type' => $grant_type, 'client_secret' => $client_secret);

 $options = array(
     'http' => array(
         'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
         'method'  => 'POST',
         'content' => http_build_query($data)
     )
 );
 $context  = stream_context_create($options);
 $result = file_get_contents($url, false, $context);

 var_dump($result);

Azure OAuth 2.0 endpoint is only accessible via HTTPS and that HTTPS is enforced via a 302 redirect if we make a request to it with plain HTTP. Azure OAuth 2.0终结点只能通过HTTPS访问,并且如果我们使用纯HTTP对其进行请求,则HTTPS是通过302重定向强制实施的。 This will cause the HTTP verb to change to GET. 这将导致HTTP动词更改为GET。 So, you'll need to use HTTPS instead of HTTP to make it work. 因此,您需要使用HTTPS而不是HTTP才能使其正常工作。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM