Example #1
0
 public function action_login()
 {
     $github_client = OAuth2_Client::factory('github');
     $redirect_uri = $_GET['redirect_uri'];
     $auth_url = $github_client->get_authentication_url($redirect_uri, array('scope' => 'user'));
     $this->redirect($auth_url);
 }
Example #2
0
 public function action_login()
 {
     $client = OAuth2_Client::factory('QQ');
     $redirect_uri = $_GET['redirect_uri'];
     $state = md5(uniqid(rand(), TRUE));
     $auth_url = $client->get_authentication_url($redirect_uri, array('state' => $state, 'scope' => 'get_user_info'));
     //var_dump($auth_url);exit;
     $this->redirect($auth_url);
 }
Example #3
0
 public function before()
 {
     parent::before();
     // Load the cookie session
     $this->session = Session::instance('cookie');
     // Get the name of the demo from the class name
     $provider = strtolower($this->api);
     // Load the provider
     $this->provider = OAuth2_Provider::factory($provider);
     // Load the client
     $this->client = OAuth2_Client::factory(Kohana::config("oauth.{$provider}"));
     if ($token = $this->session->get($this->key('access'))) {
         // Make the access token available
         $this->token = $token;
     }
 }
Example #4
0
File: User.php Project: andygoo/cms
 public function action_qqlogin()
 {
     $redirect_uri = URL::curr();
     $client = OAuth2_Client::factory('QQ');
     $user_info = $client->get_user_data($redirect_uri);
     if (empty($user_info)) {
         $this->redirect('oauth/qq/login?redirect_uri=' . urlencode($redirect_uri));
     }
     $update_user_info = Cookie::get('update_qq_user');
     if (empty($update_user_info)) {
         $m_qq = Model::factory('oauth_qq_user', 'admin');
         $qq_user_field = array('openid' => 1, 'nickname' => 1, 'gender' => 1, 'figureurl' => 1);
         $qq_user_info = array_intersect_key($user_info, $qq_user_field);
         $m_qq->replace_into($qq_user_info);
         Cookie::set('update_qq_user', 1, 86400);
     }
     $user = array('id' => 'qq_' . $user_info['openid'], 'username' => $user_info['nickname'], 'avatar' => $user_info['figureurl']);
     $auth = Auth::instance('member');
     if ($auth->force_login($user)) {
         $this->redirect(Request::$referrer);
     }
 }
Example #5
0
 /**
  * The before() method is called before controller action.
  *
  * @throws Http_Exception_404 If the provider is disabled
  *
  * @uses  Auth::logged_in
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  Config::load
  * @uses  Session::get
  */
 public function before()
 {
     parent::before();
     // Disable sidebars on user pages
     $this->_sidebars = FALSE;
     // Load the session
     $this->session = Session::instance();
     // Set the provider controller
     $this->provider = strtolower($this->request->param('provider'));
     $providers = Auth::providers();
     // Throw exception if the provider is disabled
     if (!array_key_exists($this->provider, array_filter($providers))) {
         throw new Http_Exception_404('Unsupported provider', NULL);
     }
     $this->route = $this->request->route();
     // Load the client config
     $this->provider_config = Config::load("oauth2.providers.{$this->provider}");
     $this->client = OAuth2_Client::factory($this->provider, $this->provider_config['id'], $this->provider_config['secret']);
     if ($token = $this->session->get($this->key('access'))) {
         // Make the access token available
         $this->token = $token;
     }
 }