oauth2-demo-php icon indicating copy to clipboard operation
oauth2-demo-php copied to clipboard

How to get the new acces token with refresh token

Open Deep21 opened this issue 11 years ago • 6 comments
trafficstars

Hello all,

I am trying to get a new acces token by adding the refresh token on the body request: { "grant_type":"refresh_token", "client_id":"", "client_secret":"", "refresh_token": "e1f28c7f460dfa076d675937a574c0c856f56298" }

But I got this error: { "error": "unauthorized_client", "error_description": "The grant type is unauthorized for this client_id" }

Here my PHP code: require_once('src/OAuth2/Autoloader.php'); OAuth2\Autoloader::register();

// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost" $storageD = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));

// create a storage object

$server = new OAuth2\Server($storageD); $grantTypeR = new OAuth2\GrantType\RefreshToken($storageD); $grantType = new OAuth2\GrantType\UserCredentials($storageD); $server->addGrantType($grantType); $server->addGrantType($grantTypeR);

But when I edit on the db the grant_type to refresh_token that's work !

Deep21 avatar Sep 04 '14 17:09 Deep21

Your client ID is empty... You must supply a client ID and your storage engine in turn must support that client ID / client secret combination.

bshaffer avatar Sep 05 '14 19:09 bshaffer

Even when I fill the client IDn I've got the same error: { "error": "unauthorized_client", "error_description": "The grant type is unauthorized for this client_id" }

but when I edit the grant_types table in the db to refresh_token that's work .

Deep21 avatar Sep 05 '14 22:09 Deep21

Does your server know about the client id / secret you're using?

bshaffer avatar Sep 05 '14 22:09 bshaffer

yea, I insert clientid/clientsecret in the db

Deep21 avatar Sep 05 '14 22:09 Deep21

the error The grant type is unauthorized for this client_id implies that the client_id is valid, but the grant type you're using is not. Add "refresh_token password" to your "grant_types" field in the DB, and that should fix the issue.

bshaffer avatar Sep 05 '14 23:09 bshaffer

Great ! How can I found this information ? i didnt see any informations about this issue.

Deep21 avatar Sep 06 '14 00:09 Deep21