public function getResponseData()
 {
     $refreshToken = $this->getRefreshToken();
     $acessToken = AccessToken::createAccessToken(['client_id' => $this->client_id, 'user_id' => $refreshToken->user_id, 'expires' => $this->accessTokenLifetime + time(), 'scope' => $refreshToken->scope]);
     $refreshToken->delete();
     $refreshToken = \conquer\oauth2\models\RefreshToken::createRefreshToken(['client_id' => $this->client_id, 'user_id' => $refreshToken->user_id, 'expires' => $this->refreshTokenLifetime + time(), 'scope' => $refreshToken->scope]);
     return ['access_token' => $acessToken->access_token, 'expires_in' => $this->accessTokenLifetime, 'token_type' => $this->tokenType, 'scope' => $refreshToken->scope, 'refresh_token' => $refreshToken->refresh_token];
 }
 public function getResponseData()
 {
     $accessToken = \conquer\oauth2\models\AccessToken::createAccessToken(['client_id' => $this->client_id, 'user_id' => \Yii::$app->user->id, 'expires' => $this->accessTokenLifetime + time(), 'scope' => $this->scope]);
     $refreshToken = \conquer\oauth2\models\RefreshToken::createRefreshToken(['client_id' => $this->client_id, 'user_id' => \Yii::$app->user->id, 'expires' => $this->refreshTokenLifetime + time(), 'scope' => $this->scope]);
     $fragment = ['access_token' => $accessToken->access_token, 'expires_in' => $this->accessTokenLifetime, 'token_type' => $this->tokenType, 'scope' => $this->scope, 'refresh_token' => $refreshToken->refresh_token];
     if (!empty($this->state)) {
         $fragment['state'] = $this->state;
     }
     return ['fragment' => $fragment];
 }
 public function getResponseData()
 {
     $authCode = $this->getAuthCode();
     $acessToken = AccessToken::createAccessToken(['client_id' => $this->client_id, 'user_id' => $authCode->user_id, 'expires' => $this->accessTokenLifetime + time(), 'scope' => $authCode->scope]);
     $refreshToken = RefreshToken::createRefreshToken(['client_id' => $this->client_id, 'user_id' => $authCode->user_id, 'expires' => $this->refreshTokenLifetime + time(), 'scope' => $authCode->scope]);
     /**
      * The client MUST NOT use the authorization code more than once.
      * @link https://tools.ietf.org/html/rfc6749#section-4.1.2
      */
     $authCode->delete();
     return ['access_token' => $acessToken->access_token, 'expires_in' => $this->accessTokenLifetime, 'token_type' => $this->tokenType, 'scope' => $this->scope, 'refresh_token' => $refreshToken->refresh_token];
 }
 /**
  *
  * @return \conquer\oauth2\models\RefreshToken
  */
 public function getRefreshToken()
 {
     if (is_null($this->_refreshToken)) {
         if (empty($this->refresh_token)) {
             $this->errorServer('The request is missing "refresh_token" parameter');
         }
         if (!($this->_refreshToken = \conquer\oauth2\models\RefreshToken::findOne(['refresh_token' => $this->refresh_token]))) {
             $this->errorServer('The Refresh Token is invalid');
         }
     }
     return $this->_refreshToken;
 }
 public function actionClear()
 {
     AuthorizationCode::deleteAll(['<', 'expires', time()]);
     RefreshToken::deleteAll(['<', 'expires', time()]);
     AccessToken::deleteAll(['<', 'expires', time()]);
 }
 /**
  * Check client is authorized.
  * @return bool
  * @throws Exception
  */
 public function getIsAuthorized()
 {
     if (!$this->_isAuthorized) {
         $client = $this->getResponseType()->getClient();
         $refreshToken = RefreshToken::findByClient($client);
         return $refreshToken != null;
     }
     return true;
 }
Beispiel #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRefreshTokens()
 {
     return $this->hasMany(RefreshToken::className(), ['client_id' => 'client_id']);
 }