Example #1
0
 function actionReturn()
 {
     $code = $_GET['code'];
     $postdata = http_build_query(array('grant_type' => 'authorization_code', 'client_id' => $this->app_key, 'client_secret' => $this->app_secret, 'redirect_uri' => urlencode($this->url), 'code' => $code));
     $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
     $context = stream_context_create($opts);
     $data = file_get_contents(Sohu::url_access_token(), false, $context);
     $data = json_decode($data);
     //	$data = json_decode($data);
     //	$access_token = $data->access_token;
     dump($data);
     exit;
     if ($access_token) {
         try {
             $this->auth = OAuth2::provider($this->type, array('id' => $this->app_key, 'secret' => $this->app_secret));
             $token = Token::factory('access', array('access_token' => $access_token));
             $info = $this->auth->get_user_info($token);
             if (!$info) {
                 flash('error', __('login error'));
                 $this->redirect(return_url());
                 exit;
             }
             $r = $this->member_get_third_set_user($info, $this->oauth_id, $access_token);
             flash('success', __('login success'));
             $this->redirect(return_url());
         } catch (OAuthException $e) {
             flash('error', __('login error'));
             $this->redirect(return_url());
         }
     }
     exit;
 }
Example #2
0
 function actionReturn($code)
 {
     $url = "https://github.com/login/oauth/access_token?client_id=" . $this->app_key . "&redirect_uri=" . urlencode($this->url) . "&client_secret=" . $this->app_secret . "&code=" . $_GET['code'] . "";
     $content = file_get_contents($url);
     $s = $content;
     $s = explode('&', $s);
     $d = explode('=', $s[0]);
     $access_token = $d[1];
     if ($access_token) {
         try {
             $this->auth = OAuth2::provider($this->type, array('id' => $this->app_key, 'secret' => $this->app_secret));
             $token = Token::factory('access', array('access_token' => $access_token));
             $info = $this->auth->get_user_info($token);
             $uid = $info['uid'];
             $me['id'] = $uid;
             $me['name'] = $info['name'];
             $me['email'] = $info['emial'];
             $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token);
             flash('success', __('login success'));
             $this->redirect(return_url());
         } catch (OAuthException $e) {
             flash('error', __('login error'));
             $this->redirect(return_url());
         }
     }
     exit;
 }
Example #3
0
 protected function save_login()
 {
     $access_token = $_GET['access_token'];
     if ($_GET['access_token']) {
         try {
             $this->auth = OAuth2::provider($this->type, array('id' => $this->app_key, 'secret' => $this->app_secret));
             $info = $this->auth->get_user_info($access_token);
             $uid = $info['uid'];
             $me['id'] = $uid;
             $me['name'] = $info['nickname'];
             $me['email'] = $info['email'];
             $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token);
             flash('success', __('login success'));
             $this->redirect(return_url());
         } catch (OAuthException $e) {
             flash('error', __('login error'));
             $this->redirect(return_url());
         }
     }
 }