Beispiel #1
0
 public function getUserInfo($code)
 {
     // Exchange token
     $result = Lib::doPostForm('https://accounts.google.com/o/oauth2/token', array(), array('code' => $_GET['code'], 'redirect_uri' => $this->config['redirect_uri'], 'client_id' => $this->config['client_id'], 'scope' => $scopes, 'client_secret' => $this->config['client_secret'], 'grant_type' => 'authorization_code'));
     if (null == $result) {
         return null;
     }
     $tokens = json_decode($result, true);
     // Get User Info
     $result = Lib::doRequest('GET', 'https://www.googleapis.com/oauth2/v2/userinfo', array('Authorization: ' . $tokens['token_type'] . ' ' . $tokens['access_token']), array());
     if (null == $result) {
         return null;
     }
     return json_decode($result, true);
 }
Beispiel #2
0
 public function getUserInfo($code)
 {
     // Exchange token
     $result = Lib::doRequest('GET', 'https://graph.facebook.com/oauth/access_token?' . 'client_id=' . urlencode($this->config['app_id']) . '&client_secret=' . urlencode($this->config['app_secret']) . '&redirect_uri=' . urlencode($this->config['redirect_uri']) . '&code=' . urlencode($code), array(), array());
     if (null == $result) {
         return null;
     }
     $tokens = array();
     parse_str($result, $tokens);
     // Get User Info
     $result = Lib::doRequest('GET', 'https://graph.facebook.com/me?' . 'access_token=' . urlencode($tokens['access_token']), array(), array());
     if (null == $result) {
         return null;
     }
     $user_info = json_decode($result, true);
     if (!in_array(array('id', 'email', 'name'), $user_info)) {
         return null;
     }
     $user_info['picture'] = "http://graph.facebook.com/{$user_info['id']}/picture";
     return $user_info;
 }
Beispiel #3
0
 public static function doPostForm($url, $headers, $body)
 {
     $headers[] = 'Content-type: application/x-www-form-urlencoded';
     $headers = array_unique($headers);
     return Lib::doRequest('POST', $url, $headers, http_build_query($body));
 }