oauth2-demo-php
oauth2-demo-php copied to clipboard
How to get the new acces token with refresh token
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 !
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.
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 .
Does your server know about the client id / secret you're using?
yea, I insert clientid/clientsecret in the db
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.
Great ! How can I found this information ? i didnt see any informations about this issue.