protected function AccessTokenRefresh::normalize in Simple OAuth (OAuth2) & OpenID Connect 8
Serializes the token either using the serializer or manually.
Parameters
AccessTokenInterface $token: The token.
Return value
string The serialized token.
1 call to AccessTokenRefresh::normalize()
- AccessTokenRefresh::refresh in src/
Controller/ AccessTokenRefresh.php - Controller to return the access token when a refresh token is provided.
File
- src/
Controller/ AccessTokenRefresh.php, line 89
Class
Namespace
Drupal\simple_oauth\ControllerCode
protected function normalize(AccessTokenInterface $token) {
$storage = $this
->entityManager()
->getStorage('access_token');
$ids = $storage
->getQuery()
->condition('access_token_id', $token
->id())
->condition('expire', REQUEST_TIME, '>')
->condition('resource', 'authentication')
->range(0, 1)
->execute();
if (empty($ids)) {
// TODO: Add appropriate error handling. Maybe throw an exception?
return [];
}
$refresh_token = $storage
->load(reset($ids));
if (!$refresh_token || !$refresh_token
->isRefreshToken()) {
// TODO: Add appropriate error handling. Maybe throw an exception?
return [];
}
return [
'access_token' => $token
->get('value')->value,
'token_type' => 'Bearer',
'expires_in' => $token
->get('expire')->value - REQUEST_TIME,
'refresh_token' => $refresh_token
->get('value')->value,
];
}