/** * {@inheritdoc} */ public function hasPermission($permission) { return $this->token->hasPermission($permission) ? $this->subject->hasPermission($permission) : FALSE; }
/** * Serializes the token either using the serializer or manually. * * @param AccessTokenInterface $token * The token. * * @return string * The serialized token. */ 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]; }