コード例 #1
0
ファイル: Twitter.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * begin login step
  */
 public function loginBegin()
 {
     // Initiate the Reverse Auth flow; cf. https://dev.twitter.com/docs/ios/using-reverse-auth
     if (isset($_REQUEST['reverse_auth']) && $_REQUEST['reverse_auth'] == 'yes') {
         $stage1 = $this->api->signedRequest($this->api->request_token_url, 'POST', ['x_auth_mode' => 'reverse_auth']);
         if ($this->api->http_code != 200) {
             throw new Exception("Authentication failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus($this->api->http_code), 5);
         }
         $responseObj = ['x_reverse_auth_parameters' => $stage1, 'x_reverse_auth_target' => $this->config["keys"]["key"]];
         $response = json_encode($responseObj);
         header("Content-Type: application/json", true, 200);
         echo $response;
         die;
     }
     $tokens = $this->api->requestToken($this->endpoint);
     // request tokens as received from provider
     $this->request_tokens_raw = $tokens;
     // check the last HTTP status code returned
     if ($this->api->http_code != 200) {
         throw new Exception("Authentication failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus($this->api->http_code), 5);
     }
     if (!isset($tokens["oauth_token"])) {
         throw new Exception("Authentication failed! {$this->providerId} returned an invalid oauth token.", 5);
     }
     $this->token("request_token", $tokens["oauth_token"]);
     $this->token("request_token_secret", $tokens["oauth_token_secret"]);
     // redirect the user to the provider authentication url with force_login
     if (isset($this->config['force_login']) && $this->config['force_login']) {
         Util::redirect($this->api->authorizeUrl($tokens, ['force_login' => true]));
     }
     // else, redirect the user to the provider authentication url
     Util::redirect($this->api->authorizeUrl($tokens));
 }
コード例 #2
0
ファイル: Google.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * begin login step 
  */
 public function loginBegin()
 {
     $parameters = ['scope' => $this->scope, 'access_type' => 'offline'];
     $optionals = ['scope', 'access_type', 'redirect_uri', 'approval_prompt', 'hd'];
     foreach ($optionals as $parameter) {
         if (isset($this->config[$parameter]) && !empty($this->config[$parameter])) {
             $parameters[$parameter] = $this->config[$parameter];
         }
         if (isset($this->config['scope']) && !empty($this->config['scope'])) {
             $this->scope = $this->config['scope'];
         }
     }
     Util::redirect($this->api->authorizeUrl($parameters));
 }
コード例 #3
0
ファイル: OAuth1.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * begin login step
  */
 public function loginBegin()
 {
     $tokens = $this->api->requestToken($this->endpoint);
     // request tokens as received from provider
     $this->request_tokens_raw = $tokens;
     // check the last HTTP status code returned
     if ($this->api->http_code != 200) {
         throw new Exception("Authentication failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus($this->api->http_code), 5);
     }
     if (!isset($tokens['oauth_token'])) {
         throw new Exception("Authentication failed! {$this->providerId} returned an invalid oauth token.", 5);
     }
     $this->token('request_token', $tokens['oauth_token']);
     $this->token('request_token_secret', $tokens['oauth_token_secret']);
     // redirect the user to the provider authentication url
     Util::redirect($this->api->authorizeUrl($tokens));
 }
コード例 #4
0
ファイル: Facebook.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * begin login step
  *
  * simply call Facebook::require_login().
  */
 public function loginBegin()
 {
     $parameters = ["scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page"];
     $optionals = ["scope", "redirect_uri", "display", "auth_type"];
     foreach ($optionals as $parameter) {
         if (isset($this->config[$parameter]) && !empty($this->config[$parameter])) {
             $parameters[$parameter] = $this->config[$parameter];
             //If the auth_type parameter is used, we need to generate a nonce and include it as a parameter
             if ($parameter == "auth_type") {
                 $nonce = md5(uniqid(mt_rand(), true));
                 $parameters['auth_nonce'] = $nonce;
                 $this->storage->set('fb_auth_nonce', $nonce);
             }
         }
     }
     // get the login url
     $url = $this->api->getLoginUrl($parameters);
     // redirect to facebook
     Util::redirect($url);
 }
コード例 #5
0
 public function authenticate(array $parameters = [])
 {
     if ($this->isAuthorized()) {
         return $this;
     }
     foreach (array_keys($this->authConfig['providers']) as $idpid) {
         $this->storage->delete("{$idpid}.hauth_return_to");
         $this->storage->delete("{$idpid}.hauth_endpoint");
         $this->storage->delete("{$idpid}.id_provider_params");
     }
     $this->storage->deleteMatch("{$this->providerId}.");
     $baseUrl = $this->authConfig['base_url'];
     $defaults = array('hauth_return_to' => Util::getCurrentUrl(), 'hauth_endpoint' => $baseUrl . (strpos($baseUrl, '?') ? '&' : '?') . "hauth.done={$this->providerId}", 'hauth_start_url' => $baseUrl . (strpos($baseUrl, '?') ? '&' : '?') . "hauth.start={$this->providerId}&hauth.time=" . time());
     $parameters = array_merge($defaults, (array) $parameters);
     $this->storage->set($this->providerId . '.hauth_return_to', $parameters['hauth_return_to']);
     $this->storage->set($this->providerId . '.hauth_endpoint', $parameters['hauth_endpoint']);
     $this->storage->set($this->providerId . '.id_provider_params', $parameters);
     // redirect user to start url
     Util::redirect($parameters['hauth_start_url']);
 }
コード例 #6
0
ファイル: Endpoint.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * Redirect the user to hauth_return_to (the callback url)
  */
 private function returnToCallbackUrl($providerId)
 {
     $callbackUrl = $this->storage->get("{$providerId}.hauth_return_to");
     $this->storage->delete("{$providerId}.hauth_return_to");
     $this->storage->delete("{$providerId}.hauth_endpoint");
     $this->storage->delete("{$providerId}.id_provider_params");
     Util::redirect($callbackUrl);
 }
コード例 #7
0
ファイル: OAuth2.php プロジェクト: artoodetoo/auth-sandbox
 /**
  * begin login step
  */
 public function loginBegin()
 {
     // redirect the user to the provider authentication url
     Util::redirect($this->api->authorizeUrl(['scope' => $this->scope]));
 }