msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

Document issue

Open JukkaHau opened this issue 5 years ago • 3 comments

"Microsoft Application Registration Portal (Recommended): Register a new application that authenticates using the v2.0 authentication endpoint. This endpoint authenticates both personal (Microsoft) and work or school (Azure Active Directory) accounts."

Seems to be deprecated
AB#7355

JukkaHau avatar Jan 31 '20 12:01 JukkaHau

Hello, I noticed this point too

<?php
require_once("vendor/autoload.php");
$guzzle = new \GuzzleHttp\Client();

$url = 'https://login.microsoftonline.com/iiiiiiiiiiiiiiii-iiiii-iiii-iiiii-iiiiiiiiiiiiiiiiii/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
    'form_params' => [
        'client_id' => 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx',
        'client_secret' => 'ssssssssssssssssssssss',
        'resource' => 'https://graph.microsoft.com/',
        'grant_type' => 'client_credentials',
    ],
])->getBody()->getContents());
$accessToken = $token->access_token;

var_dump($accessToken);

generates

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://login.microsoftonline.com/iiiiiiiiiiiiiiii-iiiii-iiii-iiiii-iiiiiiiiiiiiiiiiii/oauth2/v2.0/token` resulted in a `400 Bad Request` response:
{"error":"invalid_request","error_description":"AADSTS901002: The 'resource' request parameter is not supported.\r\nTrac (truncated...)
 in /root/teste/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /root/teste/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /root/teste/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /root/teste/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /root/teste/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /r in /root/teste/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

$url = 'https://login.microsoftonline.com/iiiiiiiiiiiiiiii-iiiii-iiii-iiiii-iiiiiiiiiiiiiiiiii/oauth2/token'; url /oauth2/token work normally was it right or was it somehow wrong?

(i am iniciant in api)

alexporto2200 avatar Apr 27 '20 19:04 alexporto2200

Don't remember anymore, but maybe i changed to another code example & library. Here is good example:

https://github.com/OfficeDev/Groups-API-Office-Add-in-PHP-Sample/blob/master/mygroups/AuthHelper.php "microsoft/microsoft-graph": "^1.12", "thenetworg/oauth2-azure": "^1.4"

JukkaHau avatar Apr 27 '20 20:04 JukkaHau

Hello @JukkaHau,

Could you please expand a bit more on this issue? What is deprecated?

Kind regards,

Isaac Vargas

isvargasmsft avatar Aug 01 '22 15:08 isvargasmsft

Authentication code snippet in README is fixed for v1 removing the resource parameter from the body.

v2 preview abstracts away this issue using the Authentication Provider.

Ndiritu avatar Oct 06 '22 06:10 Ndiritu