目前,我正在尝试将用户在我的网站上使用的密码(简单Php和Mysql)与我为他们创建的Microsoft帐户的密码同步。基本上,他们都有一个带有随机密码的{user_id}@mydomain.com帐户,如果他们想要使用它,他们基本上会在我网站客户端的一个专用页面上重新输入他们的密码,这样我就可以调用API并用他们自己的密码来更新随机密码。
但是,它说我没有足够的权限:
array(1) { ["error"]=> array(3) { ["code"]=> string(27) "Authorization_RequestDenied" ["message"]=> string(50) "Insufficient privileges to complete the operation." ["innerError"]=> array(2) { ["request-id"]=> string(36) "acb8b9c7-6a63-4157-8c92-de5f49a69ac8" ["date"]=> string(19) "2020-04-30T17:13:04" } } }这是我目前用于更新密码的代码,以防有帮助:
$password = array(
'forceChangePasswordNextSignIn' => false,
'forceChangePasswordNextSignInWithMfa' => false,
'password' => $_POST['password']
);
$data = array(
'passwordProfile' => $password
);
$updatePassword = patch_microsoft_graph('users/'.$userID,$data,true);我还保留了对patch_microsoft_graph()函数的引用:
function patch_microsoft_graph($scope,$data,$object) {
$access_token = get_microsoft_access_token();
if(!$scope) {
return 'no $scope';
}
$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://graph.microsoft.com/v1.0/$scope");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = [
"Authorization: $access_token",
"Host: graph.microsoft.com",
"Content-Type: application/json",
"Accept: application/json"
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
curl_close ($ch);
return json_decode($server_output,$object);
}有人能帮忙吗?提前感谢
发布于 2020-04-30 21:56:46
试一下上面的内容,让我知道它是如何进行的。
https://stackoverflow.com/questions/61529259
复制相似问题