public function Oauth::refreshAccess in Media: Acquia DAM 8
Refresh an existing access token.
Parameters
string $refresh_token: The refresh token.
Return value
array Returns an array with three keys:
- access_token: The access token used for API authorization.
- expire_time: The unix timestamp when the access token expires.
- refresh_token: The refresh token used for API authorization.
Overrides OauthInterface::refreshAccess
File
- src/
Oauth.php, line 169
Class
- Oauth
- OAuth Class.
Namespace
Drupal\media_acquiadamCode
public function refreshAccess($refresh_token) {
$this->loggerChannel
->debug('Refreshing access token for @username.', [
'@username' => $this->currentUser
->getAccountName(),
]);
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $this->httpClient
->post("{$this->damApiBase}/oauth2/token", [
'form_params' => [
'grant_type' => 'refresh_token',
'refresh_token' => $refresh_token,
'client_id' => $this->config
->get('client_id'),
'client_secret' => $this->config
->get('secret'),
'redirect_uri' => $this->urlGenerator
->generateFromRoute('media_acquiadam.auth_finish', [
'auth_finish_redirect' => $this->authFinishRedirect,
], [
'absolute' => TRUE,
]),
],
]);
$body = (string) $response
->getBody();
$body = json_decode($body);
return [
'access_token' => $body->access_token,
'expire_time' => time() + $body->expires_in,
'refresh_token' => $body->refresh_token,
];
}