0

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 League\OAuth2\Client\Provider\GenericProvider;

// 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 (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $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.

1
  • 'If you do a normal POST CURL request, Upwork returns an HTML page with the title "Just moment..."' - likely, your request via the library got the same response, and therefor it complains about it not being JSON. Such "just a moment" pages are often part of some sort of "bot protection" - but applying that to an API, would really not make much sense IMHO. I think you should contact the API provider and ask them, if they might have anything like that in place - perhaps even accidentally.
    – CBroe
    Commented Jul 10 at 11:22

0

Browse other questions tagged or ask your own question.