public function BackupMigrateDropboxAPI::obtain_refresh_token in Backup and Migrate Dropbox 7.3
Obtains a first bearer and a refresh token.
The first time we get a bearer token we do so with the just obtained, short lived, access code. This will return a short lived bearer token and a long lived refresh token which we have to store for future use. This because the subsequent bearer tokens must be obtained with the refresh token, not the access code (that will have expired by then).
Parameters
string $access_code: The short lived access code that the user obtained from the Dropbox authorization page.
string $code_verifier: The code verifier whose code challenge was used to obtain the access code.
Return value
string|null The refresh token, or null if it could not be obtained. As a side effect, the short lived bearer token that is also returned will be stored for use during the next few hours.
File
- ./
backup_migrate_dropbox.dropbox_api.inc, line 161
Class
- BackupMigrateDropboxAPI
- BackupMigrateDropboxAPI contains all the details about the Dropbox api, authorization calls, endpoints, uris, parameters, error handling, and split requests for large uploads/downloads
Code
public function obtain_refresh_token($access_code, $code_verifier) {
$parameters = [
'code' => $access_code,
'grant_type' => 'authorization_code',
'code_verifier' => $code_verifier,
'client_id' => $this
->get_app_id(),
];
try {
$response = $this
->send_message('api', 'oauth2/token', $parameters);
if (!isset($response->refresh_token)) {
throw new RuntimeException('Could not obtain a refresh token');
}
BearerTokenInfos::set($this->destination
->get_id(), $response);
return $response->refresh_token;
} catch (RuntimeException $e) {
watchdog('backup_migrate', 'Backup Migrate Dropbox Error: ' . $e
->getMessage(), [], WATCHDOG_ERROR);
drupal_set_message('Backup Migrate Dropbox Error: ' . $e
->getMessage(), 'error');
return NULL;
}
}