OAuth2 Client Database
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
OAuth2 Client Database integrates OAuth2 Client into Drupal and allows you to store the token data in the database storage instead of session storage.
Dependencies
Situation
Let's imagine, you use password grant and generate token on hook_user_login where you put (username and plain password) like this:
$client_id = "oauth2_client:{$user->uid}";
$oauth2_config = array(
'token_endpoint' => $server_url . '/oauth2/token',
'auth_flow' => 'user-password',
'client_id' => $client_id,
'client_secret' => '12345',
'username' => $username,
'password' => $password,
);
try {
$oauth2_client = new OAuth2Client($oauth2_config, $client_id);
$access_token = $oauth2_client->getAccessToken();
}
catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
then, the token data will be stored in the session. Everything will work like a charm until your session won't be regenerated.
For some reason, you want to use persistent_login or some other modules which make your session available until the browser is closed.
When the session is destroyed persistent_login will try to Log In user again by the Persistent Login cookie. In that case, you will get an error like "Failed to get an access token..." because there is no plain password.
To fix it, you need to store access token in the database.
Solution
This Drupal module allows you to use an OAuth2 Client with the database storage. So, just install and enable the module oauth2_client_db besides oauth2_client and use the class OAuth2DatabaseClient instead of OAuth2Client.