Esempio n. 1
0
 public function associateScope(SessionEntity $session, ScopeEntity $scope)
 {
     $session = Session::where('id', '=', $session->getId())->first();
     $scope = Scope::where('identifier', '=', $scope->getId())->first();
     if ($session && $scope) {
         $session->scopes()->attach($scope);
     }
 }
Esempio n. 2
0
 /**
  * Triggers the given list of tasks
  * on each session if task
  * is supported on sessions
  */
 public function foreachSession($tasks)
 {
     $sessions = Session::get();
     $this->outputStr("Analyzing " . sizeof($sessions) . " sessions...");
     $n_deleted = 0;
     foreach ($sessions as $session) {
         if (in_array('delete_lonely_session', $tasks)) {
             if ($this->deleteLonelySession($session)) {
                 $n_deleted++;
             }
         }
     }
     if (in_array('delete_lonely_session', $tasks) && $n_deleted > 0) {
         $this->outputStr(" deleted " . $n_deleted . " lonely sessions.");
     }
     $this->outputStr("\n\n");
 }
Esempio n. 3
0
 /**
  * It creates an access token, a session, and links
  * scopes mentionned in $scopes to the session and
  * access token, it finally returns the new access token
  *
  * It associates the 'webapp' app
  */
 public static function createAccessTokenFromUserId($user_id, $scopes, $ttl = 3600)
 {
     $user = User::where('id', '=', $user_id)->first();
     if (!$user) {
         return false;
     }
     $session = new Session();
     $session->owner_type = 'user';
     $session->owner_id = $user->id;
     $session->app_id = 'webapp';
     $session->save();
     $accessToken = new AccessToken();
     $accessToken->session_id = $session->id;
     $accessToken->token = SecureKey::generate();
     $accessToken->expire_time = DB::raw('FROM_UNIXTIME(' . ($ttl + time()) . ')');
     $accessToken->save();
     foreach ($scopes as $_scope) {
         $scope = Scope::where('identifier', '=', $_scope)->first();
         if ($scope) {
             $session->scopes()->attach($scope);
             $accessToken->scopes()->attach($scope);
         }
     }
     $refreshToken = new RefreshToken();
     $refreshToken->access_token_id = $accessToken->id;
     $refreshToken->token = SecureKey::generate();
     $refreshToken->expire_time = DB::raw('FROM_UNIXTIME(' . (604800 + time()) . ')');
     $refreshToken->save();
     return ["token" => $accessToken->token, "refresh_token" => $refreshToken->token, "ttl" => $ttl];
 }