/** * New OAuth2 Client */ function QBox_OAuth2_NewClient() { global $QBOX_ACCESS_KEY, $QBOX_SECRET_KEY; $client = new OAuth2_Client('a75604760c4da4caaa456c0c5895c061c3065c5a', '75df554a39f58accb7eb293b550fa59618674b7d'); $client->setAccessTokenType($client->access_token_qbox, $QBOX_SECRET_KEY); $client->setAccessToken($QBOX_ACCESS_KEY); return $client; }
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); }
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); }
/** * refresh access token * * @param OAuth2_Token $token */ public function refreshAccessToken(OAuth2_Token $token) { if (!$token->getRefreshToken()) { throw new OAuth2_Exception('could not refresh access token, no refresh token available'); } $parameters = array('grant_type' => 'refresh_token', 'type' => 'web_server', 'client_id' => $this->_client->getClientKey(), 'client_secret' => $this->_client->getClientSecret(), 'refresh_token' => $token->getRefreshToken()); $http = new OAuth2_HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters)); $http->execute(); $this->_parseAccessTokenResponse($http); }
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; } }
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); } }
/** * 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; } }