public function RevocableTokenRepositoryTrait::persistNew in Simple OAuth (OAuth2) & OpenID Connect 8.4
Same name and namespace in other branches
- 8.2 src/Repositories/RevocableTokenRepositoryTrait.php \Drupal\simple_oauth\Repositories\RevocableTokenRepositoryTrait::persistNew()
- 8.3 src/Repositories/RevocableTokenRepositoryTrait.php \Drupal\simple_oauth\Repositories\RevocableTokenRepositoryTrait::persistNew()
- 5.x src/Repositories/RevocableTokenRepositoryTrait.php \Drupal\simple_oauth\Repositories\RevocableTokenRepositoryTrait::persistNew()
3 calls to RevocableTokenRepositoryTrait::persistNew()
- AccessTokenRepository::persistNewAccessToken in src/
Repositories/ AccessTokenRepository.php - AuthCodeRepository::persistNewAuthCode in src/
Repositories/ AuthCodeRepository.php - RefreshTokenRepository::persistNewRefreshToken in src/
Repositories/ RefreshTokenRepository.php
File
- src/
Repositories/ RevocableTokenRepositoryTrait.php, line 51
Class
- RevocableTokenRepositoryTrait
- Common methods for token repositories on different grants.
Namespace
Drupal\simple_oauth\RepositoriesCode
public function persistNew($token_entity) {
if (!is_a($token_entity, static::$entityInterface)) {
throw new \InvalidArgumentException(sprintf('%s does not implement %s.', get_class($token_entity), static::$entityInterface));
}
$values = $this->serializer
->normalize($token_entity);
$values['bundle'] = static::$bundleId;
$new_token = $this->entityTypeManager
->getStorage(static::$entityTypeId)
->create($values);
if ($token_entity instanceof RefreshTokenEntityInterface) {
$access_token = $token_entity
->getAccessToken();
if (!empty($access_token
->getUserIdentifier())) {
$new_token
->set('auth_user_id', $access_token
->getUserIdentifier());
}
}
$new_token
->save();
}