I have already received the authorization code. But the token cannot be obtained.
Documentation:
https://www.upwork.com/developer/documentation/graphql/api/docs/index.html#auth-authorizationCodeGrant
Endpoint
POST https://api.upwork.com/graphql/api/v3/oauth2/token
I do OAuth2 authorization using the league/oauth2-client library
My code:
include "lib/League/autoload.php";
use LeagueOAuth2ClientProviderGenericProvider;
// OAuth2
$provider = new GenericProvider([
'clientId' => '*****',
'clientSecret' => '*****',
'redirectUri' => '********',
'urlAccessToken' => 'https://api.upwork.com/graphql/api/v3/oauth2/token',
'urlAuthorize' => '',
'urlResourceOwnerDetails' => '',
]);
try {
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => '*******'
]);
echo 'Access Token: ' . $accessToken->getToken() . "<br>";
echo 'Expires: ' . $accessToken->getExpires() . "<br>";
} catch (LeagueOAuth2ClientProviderExceptionIdentityProviderException $e) {
exit($e->getMessage());
}
After execution, I get an error:
Fatal error: Uncaught UnexpectedValueException: Invalid response received from Authorization Server. Expected JSON. in /lib/League/league/oauth2-client/src/Provider/AbstractProvider.php:637
If you do a normal POST CURL request, Upwork returns an HTML page with the title “Just moment…” and other content and nothing else happens..
Please tell me how to get this token.