php - PHP Office 365 图形认证
问题描述
我在通过 PHP 验证和访问 Microsoft Graph API 时遇到问题。
我已经使用 clientID 和 clientSecret 代码以及正确的 redirectURI 设置了 Azure 应用程序。
当我尝试在 Web 浏览器中查看此 PHP 代码时,我收到 HTTP 500 错误。
我有以下代码:
<?php
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$clientSecret = 'SAMPLE';
$clientId = 'SAMPLE';
$redirectUri = 'SAMPLE';
$tenantId = 'SAMPLE';
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$accessToken = $token->access_token;
$graph = new Graph();
$graph->setAccessToken($accessToken);
$user = $graph->createRequest("GET", "/me")
->setReturnType(Model\User::class)
->execute();
echo "<script type='text/javascript'>alert('$user->getGivenName()');</script>";
?>
我希望有人可以提供任何有用的东西,因为我似乎在这方面的任何地方都找不到文档。
我还必须通过 SSH 在虚拟主机上安装 composer.phar,并且不确定它是否在正确的目录中正确运行。它确实安装了所有必需的插件,例如 guzzleHTTP、Microsoft Graph 和 oauth2。
解决方案
推荐阅读
- sparql - 来自维基数据的近似匹配
- vulkan - 为什么我的代码中必须有“vkClearValue”才能使其正常工作?
- jquery - Jquery自动完成未在asp.net页面中显示选定列表
- android - 来自 Google 的 Youtube Data API v3 不活动电子邮件
- javascript - 使用 rem 时计算 html 元素字体大小的最佳方法是什么?
- javascript - 如何使用 PHP 和 Javascript 更新聊天室
- python - 如何防止我的标题与我的 y 轴重叠?
- c++ - c++帮助我理解为什么没有输出
- laravel - Laravel:如何根据通知数组中存在的数据删除数据库通知
- python - Python请求 - 响应编码不正确