Ejemplo n.º 1
0
 /**
  * 
  * @param type $client_id
  * @param type $authorization_code
  * @param type $access_token
  * @param type $expires_in
  * @return type
  */
 public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
 {
     $user_uuid = AuthorizationCode::findUserUuid($authorization_code);
     $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);
     if (!$model) {
         $model = new OauthAccessToken();
         $model->client_id = $client_id;
         $model->user_uuid = $user_uuid;
     }
     $model->access_token = $access_token;
     $model->expires = date('Y-m-d H:i:s', time() + $expires_in);
     return $model->save();
 }
Ejemplo n.º 2
0
 /**
  * Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
  * Do not need to check the Client ID & Access Token.
  * @param Request $request the current request
  * @param Action $action the action to be executed
  * @param integer $allowance the number of allowed requests remaining.
  * @param integer $timestamp the current timestamp.
  */
 public function saveAllowance($request, $action, $allowance, $timestamp)
 {
     $access_token = \common\models\OauthAccessToken::findOne(['client_id' => $request->post('client_id'), 'access_token' => $request->post('access_token')]);
     if (!$access_token) {
         return false;
     }
     $endpoint = $action->controller->route;
     $api_ratelimiter = ApiRatelimiter::findOne(['client_id' => $request->post('client_id'), 'api_endpoint' => $endpoint, 'user_uuid' => $access_token->user_uuid]);
     if (!$api_ratelimiter) {
         $api_ratelimiter = new ApiRatelimiter(['client_id' => $request->post('client_id'), 'api_endpoint' => $endpoint, 'user_uuid' => $access_token->user_uuid]);
     }
     $api_ratelimiter->allowed_remaining = $allowance;
     $api_ratelimiter->last_timestamp = $timestamp;
     return $api_ratelimiter->save();
 }