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']);
 }