Ejemplo n.º 1
0
 /**
  * @return AProfile
  * @throws AuthException
  */
 public function auth()
 {
     if (!isset($_GET['code'])) {
         throw new AuthException();
     }
     $Info = json_decode(Curl::post('https://accounts.google.com/o/oauth2/token', ['client_id' => $this->getUid(), 'redirect_uri' => $this->getUri(), 'client_secret' => $this->getKey(), 'grant_type' => 'authorization_code', 'code' => $_GET['code']]), true);
     if (!isset($Info['access_token'])) {
         throw new AuthException();
     }
     $Data = json_decode(Curl::get('https://www.googleapis.com/oauth2/v1/userinfo', ['access_token' => $Info['access_token']]), true);
     if (!isset($Data['id'])) {
         throw new AuthException();
     }
     return new Profile($Data, $Info['access_token']);
 }
Ejemplo n.º 2
0
Archivo: Fb.php Proyecto: eggbe/soauth
 /**
  * @return AProfile
  * @throws AuthException
  */
 public final function auth()
 {
     if (!isset($_GET['code'])) {
         throw new AuthException();
     }
     parse_str(Curl::get('https://graph.facebook.com/oauth/access_token', ['client_id' => $this->getUid(), 'redirect_uri' => $this->getUri(), 'client_secret' => $this->getKey(), 'code' => $_GET['code']]), $Info);
     if (!isset($Info['access_token'])) {
         throw new AuthException();
     }
     $Data = json_decode(Curl::get('https://graph.facebook.com/me', ['access_token' => $Info['access_token'], 'fields' => 'email,first_name,last_name,name,gender,timezone']), true);
     if (!isset($Data['id'])) {
         throw new AuthException();
     }
     return new Profile($Data, $Info['access_token']);
 }
Ejemplo n.º 3
0
 /**
  * @return AProfile
  * @throws AuthException
  */
 public final function auth()
 {
     if (!isset($_GET['code'])) {
         throw new AuthException();
     }
     parse_str(Curl::get('https://github.com/login/oauth/access_token', ['client_id' => $this->getUid(), 'client_secret' => $this->getKey(), 'redirect_uri' => $this->getUri(), 'code' => $_GET['code']]), $Info);
     if (!isset($Info['access_token'])) {
         throw new AuthException();
     }
     $Data = json_decode(Curl::get('https://api.github.com/user', ['access_token' => $Info['access_token']], ['User-Agent' => 'eggbe']), true);
     if (!isset($Data['id'])) {
         throw new AuthException();
     }
     return new Profile($Data, $Info['access_token']);
 }
Ejemplo n.º 4
0
Archivo: Vk.php Proyecto: eggbe/soauth
 /**
  * auth and return bool result of authentication
  * @throws AuthException
  * @return bool
  */
 public function auth()
 {
     if (!isset($_GET['code'])) {
         throw new AuthException();
     }
     $Info = json_decode(Curl::get('https://oauth.vk.com/access_token', ['client_id' => $this->getUid(), 'redirect_uri' => $this->getUri(), 'client_secret' => $this->getKey(), 'scope' => 'email', 'code' => $_GET['code']]), true);
     if (!isset($Info['access_token'])) {
         throw new AuthException();
     }
     $Data = json_decode(Curl::get('https://api.vk.com/method/users.get', ['uids' => $Info['user_id'], 'fields' => 'uid,first_name,last_name,sex,bdate,photo_big,timezone,lang', 'access_token' => $Info['access_token']]), true);
     if (!is_array($Data['response'])) {
         throw new AuthException();
     }
     $Data = array_shift($Data['response']);
     if (!isset($Data['uid'])) {
         throw new AuthException();
     }
     return new Profile($Data, $Info['access_token']);
 }