/**
  * Creates and returns access token for a user
  * @param  AdvancedUserInterface $user [description]
  * @return [type]                      [description]
  */
 public function generateAccessToken(AdvancedUserInterface $user)
 {
     if (is_null($user->getOAuthClient()->getId())) {
         throw new \Exception('User must have an OAuth Client', 500);
     }
     // Search valid token
     $oauth_access_token = $this->oauth_manipulator->getValidTokenForClient($user->getOAuthClient());
     if (!is_null($oauth_access_token)) {
         return $oauth_access_token->getToken();
     }
     // Or else, creates a new one
     // Forge request to satisfy OAuth2 server
     $request = new Request();
     $request->query->add(['client_id' => $user->getOAuthClient()->getPublicId(), 'response_type' => OAuth2::RESPONSE_TYPE_ACCESS_TOKEN, 'redirect_uri' => $user->getOAuthClient()->getRedirectUris()[0]]);
     $response = $this->oauth2->finishClientAuthorization(true, $user, $request, null);
     if ($response instanceof Response) {
         $location = str_replace('#', '?', $response->headers->get('location'));
         $query_string = parse_url($location, PHP_URL_QUERY);
         parse_str($query_string, $queries);
         if (isset($queries['access_token'])) {
             $access_token = $queries['access_token'];
             return $access_token;
         }
     } else {
         throw new Exception("Token creation ; unknown response type : " . get_class($response), 500);
     }
 }
 /**
  * Retourne l'image principale de l'utilisateur
  * @param  FacebookSession       $session [description]
  * @param  AdvancedUserInterface $user    [description]
  * @return [type]                         [description]
  */
 public function getUserPicture(FacebookSession $session, AdvancedUserInterface $user)
 {
     if (!is_null($user->getFacebookId())) {
         $request = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => false, 'type' => 'large']);
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         return $graphObject->getProperty('url');
     }
 }
Exemplo n.º 3
0
 public static function getRoleLevel(AdvancedUserInterface $user)
 {
     if ($Roles = $user->getRoles()) {
         foreach ($Roles as $Role) {
             $RoleLevel[] = $Role->getParent();
         }
         return min($RoleLevel);
     }
     return NULL;
 }
Exemplo n.º 4
0
 /**
  * @param AdvancedUserInterface $user
  * @param $area
  */
 public function login(AdvancedUserInterface $user, $area)
 {
     $request = $this->container->get('request');
     // $area is the name of the firewall in your security.yml
     $token = new UsernamePasswordToken($user, $user->getPassword(), $area, $user->getRoles());
     $this->container->get("security.token_storage")->setToken($token);
     // Fire the login event
     // Logging the user in above the way we do it doesn't do this automatically
     $event = new InteractiveLoginEvent($request, $token);
     $this->container->get("event_dispatcher")->dispatch('security.interactive_login', $event);
 }
Exemplo n.º 5
0
 public function isEqualTo(AdvancedUserInterface $user)
 {
     if (!$user instanceof AdvancedUserInterface) {
         return false;
     }
     if ($this->password !== $user->getPassword()) {
         return false;
     }
     if ($this->getSalt() !== $user->getSalt()) {
         return false;
     }
     if ($this->username !== $user->getUsername()) {
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * @return boolean
  */
 public function equals(AdvancedUserInterface $user)
 {
     return $this->getUsername() == $user->getUsername();
 }
Exemplo n.º 7
0
 public function isEqualTo(AdvancedUserInterface $user)
 {
     return $this->username === $user->getUsername();
 }
Exemplo n.º 8
0
 public function isEqualTo(AdvancedUserInterface $user)
 {
     return $this->id === $user->getId();
 }
 /**
  * generateRegistrationRequest
  * @param AdvancedUserInterface $user
  * @return string
  **/
 public function generateRegistrationRequest(AdvancedUserInterface $user)
 {
     return $this->u2f->getRegisterData($user->getU2FKeys()->toArray());
 }