Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Microsoft Azure oauth2令牌POST方法不工作_Php_Azure_Authentication_Oauth 2.0_Http Post - Fatal编程技术网

PHP Microsoft Azure oauth2令牌POST方法不工作

PHP Microsoft Azure oauth2令牌POST方法不工作,php,azure,authentication,oauth-2.0,http-post,Php,Azure,Authentication,Oauth 2.0,Http Post,这简直快把我逼疯了 如果方法是POST,为什么Azure返回“AADSTS90056:此端点仅接受POST、OPTIONS请求。收到GET请求”错误 代码: Azure OAuth 2.0端点只能通过HTTPS访问,如果我们使用普通HTTP向其发出请求,则通过302重定向强制使用HTTPS。这将导致HTTP谓词更改为获取。因此,您需要使用HTTPS而不是HTTP来使其工作 您能检查一下您的网络呼叫,看看发送的请求是否真的是POST吗? $url='http://login.microsofton

这简直快把我逼疯了

如果方法是POST,为什么Azure返回“AADSTS90056:此端点仅接受POST、OPTIONS请求。收到GET请求”错误

代码:


Azure OAuth 2.0端点只能通过HTTPS访问,如果我们使用普通HTTP向其发出请求,则通过302重定向强制使用HTTPS。这将导致HTTP谓词更改为获取。因此,您需要使用HTTPS而不是HTTP来使其工作


您能检查一下您的网络呼叫,看看发送的请求是否真的是POST吗?
$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);