hello ,
I've tried to access my onedrive account using a php script that I need for a web application. However I get the following error:
Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error: POST https://login.microsoftonline.com/......./oauth2/token
resulted in a 500 Internal Server Error
response:
{"error":"server_error","error_description":"AADSTS90036: An unexpected, non-retryable error stemming from the directory (truncated...)
in /home/weblamp/public_html/onedrive/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
0 /home/weblamp/public_html/onedrive/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
1 /home/weblamp/public_html/onedrive/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
2 /home/weblamp/public_html/onedrive/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
3 /home/webla in /home/weblamp/public_html/onedrive/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
Below my script :
require DIR . '/vendor/autoload.php';
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$target_dir = "downloads/";
echo "<pre>";
$guzzle = new \GuzzleHttp\Client();
$tenantId = 'your_tenanet_id, e4c9ab4e-****-****-****-230ba2a757fb';
$clientId = 'your_app_id_registered_in_portal, dc175b96-****-****-****-ea03e56da5e7';
$clientSecret = 'app_key_generated_in_portal, /pGggH************************Zr732';
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token';
$user_token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'password',
'username' => '.....',
'password' => '...'
],
])->getBody()->getContents());
$user_accessToken = $user_token->access_token;
echo $user_accessToken;
I created a Azure directory app, set up the permissions, got the right app id, tenant id, secret however the issue still persist.
Please help.