Skip to content
Snippets Groups Projects

Draft: Resolve #2923419 "Method to use 2.x"

2 files
+ 70
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -191,6 +191,58 @@ abstract class OpenIDConnectClientBase extends PluginBase implements OpenIDConne
}
}
/**
* {@inheritdoc}
*/
public function refreshTokens(string $refresh_token): ?array {
// Exchange a refresh token for new tokens.
$endpoints = $this->getEndpoints();
$request_options = [
'form_params' => [
'refresh_token' => $refresh_token,
'client_id' => $this->configuration['client_id'],
'client_secret' => $this->configuration['client_secret'],
'grant_type' => 'refresh_token',
],
'headers' => [
'Accept' => 'application/json',
],
];
if ($scopes = implode(' ', $this->getClientScopes())) {
$request_options['form_params']['scope'] = $scopes;
}
/* @var \GuzzleHttp\ClientInterface $client */
$client = $this->httpClient;
try {
$response = $client->post($endpoints['token'], $request_options);
$response_data = json_decode((string) $response->getBody(), TRUE);
// Expected result.
$tokens = [
'id_token' => isset($response_data['id_token']) ? $response_data['id_token'] : NULL,
'access_token' => isset($response_data['access_token']) ? $response_data['access_token'] : NULL,
];
if (array_key_exists('expires_in', $response_data)) {
$tokens['expire'] = REQUEST_TIME + $response_data['expires_in'];
}
if (array_key_exists('refresh_token', $response_data)) {
$tokens['refresh_token'] = $response_data['refresh_token'];
}
return $tokens;
}
catch (Exception $e) {
$variables = [
'@message' => 'Could not refresh tokens',
'@error_message' => $e->getMessage(),
];
$this->loggerFactory->get('openid_connect_' . $this->pluginId)
->error('@message. Details: @error_message', $variables);
return FALSE;
}
}
/**
* {@inheritdoc}
*/
Loading