/** * Encodes a token from parameters and returns an instance of this class. * * The encoded token can be obtained using the {@link getEncoded()} method. * * @param Authorization $authorization the authorisation to use to create * this token * @param array $scope the scope of this token - this must be a subset * of the scope provided in `$authorization` * @param TokenSource $source if the token is created from a previous authorisation * code or refresh token, the ID of those artefacts * @param array $additional any additional data to be stored on the server for this token * @return RefreshToken|null */ public static function create($authorization, $scope = array(), $source = NULL, $additional = array()) { $token = new RefreshToken(); $token->init($authorization, $scope, Token::TTL_PERPETUAL, $source, $additional); $token->encode(); $token->is_parsed = true; return $token; }
/** * Revokes all access tokens for a give refresh token * @param $value refresh token value * @param bool $is_hashed * @return bool|void */ public function clearAccessTokensForRefreshToken($value, $is_hashed = false) { $hashed_value = !$is_hashed ? Hash::compute('sha256', $value) : $value; $res = false; $cache_service = $this->cache_service; $this->tx_service->transaction(function () use($hashed_value, &$res, &$cache_service) { $refresh_token_db = DBRefreshToken::where('value', '=', $hashed_value)->first(); if (!is_null($refresh_token_db)) { $access_tokens_db = DBAccessToken::where('refresh_token_id', '=', $refresh_token_db->id)->get(); if (!count($access_tokens_db)) { $res = true; } foreach ($access_tokens_db as $access_token_db) { $res = $cache_service->delete($access_token_db->value); $client = $access_token_db->client()->first(); $res = $cache_service->deleteMemberSet($client->client_id . TokenService::ClientAccessTokenPrefixList, $access_token_db->value); $access_token_db->delete(); } } }); return $res; }
public function deleteRefreshToken(RefreshToken $refreshToken) { if (!isset($_SESSION['php-oauth-client']['refresh_token'])) { return false; } foreach ($_SESSION['php-oauth-client']['refresh_token'] as $k => $t) { $token = unserialize($t); if ($refreshToken->getRefreshToken() !== $token->getRefreshToken()) { continue; } unset($_SESSION['php-oauth-client']['refresh_token'][$k]); return true; } return false; }
public function getResponseData() { $acessToken = AccessToken::createAccessToken(['client_id' => $this->client_id, 'user_id' => \Yii::$app->user->id, 'expires' => $this->accessTokenLifetime + time(), 'scope' => $this->scope]); $refreshToken = RefreshToken::createRefreshToken(['client_id' => $this->client_id, 'user_id' => \Yii::$app->user->id, 'expires' => $this->refreshTokenLifetime + time(), 'scope' => $this->scope]); return ['access_token' => $acessToken->access_token, 'expires_in' => $this->accessTokenLifetime, 'token_type' => $this->tokenType, 'scope' => $this->scope, 'refresh_token' => $refreshToken->refresh_token]; }