mirror of
https://github.com/e107inc/e107.git
synced 2025-06-04 01:45:15 +02:00
hybridAuth debugging improvements.
This commit is contained in:
parent
6a2c29de5e
commit
04f92e5335
@ -1542,11 +1542,13 @@ $social_external = array(
|
||||
"Github" => "https://github.com/settings/applications/new",
|
||||
);
|
||||
|
||||
$testUrl = SITEURL."?route=system/xup/test";
|
||||
|
||||
$text .= "
|
||||
<fieldset class='e-hideme' id='core-prefs-sociallogin'>
|
||||
<legend>Social Options</legend>
|
||||
<div class='alert alert-warning'>Note: This section requires further testing</div>
|
||||
<div class='alert alert-warning'>Note: This section requires further testing.<br />You may test with the following URL:
|
||||
<a href='".$testUrl."' rel='external'>".$testUrl."</a></div>
|
||||
<table class='table adminform'>
|
||||
<colgroup>
|
||||
<col class='col-label' />
|
||||
|
@ -82,20 +82,44 @@ class core_system_xup_controller extends eController
|
||||
|
||||
public function actionTest()
|
||||
{
|
||||
echo 'Login controller<br /><br />';
|
||||
echo '<h3>Social Login Tester</h3>';
|
||||
|
||||
if(getperms('0'))
|
||||
{
|
||||
echo e107::getMessage()->addError("Please logout of e107 before testing the new-user login/signup procedure.")->render();
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_GET['lgt']))
|
||||
{
|
||||
e107::getUser()->logout();
|
||||
}
|
||||
|
||||
echo 'Logged in: '.(e107::getUser()->isUser() ? 'true' : 'false');
|
||||
echo 'Logged in: '.(e107::getUser()->isUser() ? '<span class="label label-success">true</span>' : '<span class="label label-danger">false</span>');
|
||||
|
||||
$provider = e107::getUser()->getProvider();
|
||||
if($provider) print_a($provider->getUserProfile());
|
||||
|
||||
echo '<br /><br /><a href="'.e107::getUrl()->create('system/xup/test?lgt').'">Test logout</a>';
|
||||
|
||||
|
||||
$providers = e107::getPref('social_login', array());
|
||||
|
||||
foreach($providers as $key=>$var)
|
||||
{
|
||||
if($var['enabled'] == 1)
|
||||
{
|
||||
echo '<h3>'.$key.'</h3><ul>';
|
||||
echo '<li><a href="'.e107::getUrl()->create('system/xup/login?provider='.$key.'&back='.base64_encode(e_REQUEST_URL)).'">Test login only with '.$key.'</a></li>';
|
||||
echo '<li><a href="'.e107::getUrl()->create('system/xup/signup?provider='.$key.'&back='.base64_encode(e_REQUEST_URL)).'">Test signup/login with '.$key.'</a></li>';
|
||||
echo "</ul>";
|
||||
}
|
||||
|
||||
// print_a($var);
|
||||
}
|
||||
|
||||
echo '<br /><br /><a href="'.e107::getUrl()->create('system/xup/test?lgt').'">Test logout</a>';
|
||||
|
||||
/*
|
||||
echo '<h3>Facebook</h3>';
|
||||
echo '<br /><a href="'.e107::getUrl()->create('system/xup/login?provider=Facebook').'">Test login with Facebook</a>';
|
||||
echo '<br /><a href="'.e107::getUrl()->create('system/xup/signup?provider=Facebook').'">Test signup with Facebook</a>';
|
||||
@ -103,6 +127,8 @@ class core_system_xup_controller extends eController
|
||||
echo '<h3>Twitter</h3>';
|
||||
echo '<br /><a href="'.e107::getUrl()->create('system/xup/login?provider=Twitter').'">Test login with Twitter</a>';
|
||||
echo '<br /><a href="'.e107::getUrl()->create('system/xup/signup?provider=Twitter').'">Test signup with Twitter</a>';
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
public function actionEndpoint()
|
||||
|
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* HybridAuth
|
||||
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
|
||||
* (c) 2009-2014, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
|
||||
* (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
|
||||
*/
|
||||
|
||||
// A service client for the OAuth 2 flow.
|
||||
@ -46,8 +46,8 @@ class OAuth2Client
|
||||
public function __construct( $client_id = false, $client_secret = false, $redirect_uri='' )
|
||||
{
|
||||
$this->client_id = $client_id;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
}
|
||||
|
||||
public function authorizeUrl( $extras = array() )
|
||||
@ -74,9 +74,9 @@ class OAuth2Client
|
||||
"redirect_uri" => $this->redirect_uri,
|
||||
"code" => $code
|
||||
);
|
||||
|
||||
|
||||
$response = $this->request( $this->token_url, $params, $this->curl_authenticate_method );
|
||||
|
||||
|
||||
$response = $this->parseRequestResult( $response );
|
||||
|
||||
if( ! $response || ! isset( $response->access_token ) ){
|
||||
@ -84,35 +84,35 @@ class OAuth2Client
|
||||
}
|
||||
|
||||
if( isset( $response->access_token ) ) $this->access_token = $response->access_token;
|
||||
if( isset( $response->refresh_token ) ) $this->refresh_token = $response->refresh_token;
|
||||
if( isset( $response->expires_in ) ) $this->access_token_expires_in = $response->expires_in;
|
||||
|
||||
if( isset( $response->refresh_token ) ) $this->refresh_token = $response->refresh_token;
|
||||
if( isset( $response->expires_in ) ) $this->access_token_expires_in = $response->expires_in;
|
||||
|
||||
// calculate when the access token expire
|
||||
if( isset($response->expires_in)) {
|
||||
$this->access_token_expires_at = time() + $response->expires_in;
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function authenticated()
|
||||
{
|
||||
if ( $this->access_token ){
|
||||
if ( $this->token_info_url && $this->refresh_token ){
|
||||
// check if this access token has expired,
|
||||
$tokeninfo = $this->tokenInfo( $this->access_token );
|
||||
// check if this access token has expired,
|
||||
$tokeninfo = $this->tokenInfo( $this->access_token );
|
||||
|
||||
// if yes, access_token has expired, then ask for a new one
|
||||
if( $tokeninfo && isset( $tokeninfo->error ) ){
|
||||
$response = $this->refreshToken( $this->refresh_token );
|
||||
$response = $this->refreshToken( $this->refresh_token );
|
||||
|
||||
// if wrong response
|
||||
if( ! isset( $response->access_token ) || ! $response->access_token ){
|
||||
throw new Exception( "The Authorization Service has return an invalid response while requesting a new access token. given up!" );
|
||||
throw new Exception( "The Authorization Service has return an invalid response while requesting a new access token. given up!" );
|
||||
}
|
||||
|
||||
// set new access_token
|
||||
$this->access_token = $response->access_token;
|
||||
$this->access_token = $response->access_token;
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,10 +122,10 @@ class OAuth2Client
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and sign an oauth for provider api
|
||||
/**
|
||||
* Format and sign an oauth for provider api
|
||||
*/
|
||||
public function api( $url, $method = "GET", $parameters = array() )
|
||||
public function api( $url, $method = "GET", $parameters = array() )
|
||||
{
|
||||
if ( strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0 ) {
|
||||
$url = $this->api_base_url . $url;
|
||||
@ -135,31 +135,31 @@ class OAuth2Client
|
||||
$response = null;
|
||||
|
||||
switch( $method ){
|
||||
case 'GET' : $response = $this->request( $url, $parameters, "GET" ); break;
|
||||
case 'GET' : $response = $this->request( $url, $parameters, "GET" ); break;
|
||||
case 'POST' : $response = $this->request( $url, $parameters, "POST" ); break;
|
||||
}
|
||||
|
||||
if( $response && $this->decode_json ){
|
||||
$response = json_decode( $response );
|
||||
$response = json_decode( $response );
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* GET wrapper for provider apis request
|
||||
*/
|
||||
function get( $url, $parameters = array() )
|
||||
{
|
||||
return $this->api( $url, 'GET', $parameters );
|
||||
}
|
||||
return $this->api( $url, 'GET', $parameters );
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* POST wrapper for provider apis request
|
||||
*/
|
||||
function post( $url, $parameters = array() )
|
||||
{
|
||||
return $this->api( $url, 'POST', $parameters );
|
||||
return $this->api( $url, 'POST', $parameters );
|
||||
}
|
||||
|
||||
// -- tokens
|
||||
@ -175,12 +175,12 @@ class OAuth2Client
|
||||
{
|
||||
$params = array(
|
||||
"client_id" => $this->client_id,
|
||||
"client_secret" => $this->client_secret,
|
||||
"client_secret" => $this->client_secret,
|
||||
"grant_type" => "refresh_token"
|
||||
);
|
||||
|
||||
foreach($parameters as $k=>$v ){
|
||||
$params[$k] = $v;
|
||||
$params[$k] = $v;
|
||||
}
|
||||
|
||||
$response = $this->request( $this->token_url, $params, "POST" );
|
||||
@ -215,8 +215,8 @@ class OAuth2Client
|
||||
}
|
||||
|
||||
if( $type == "POST" ){
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, $params );
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($params, '', '&') );
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
@ -231,7 +231,7 @@ class OAuth2Client
|
||||
|
||||
curl_close ($ch);
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function parseRequestResult( $result )
|
||||
|
@ -861,8 +861,10 @@ class e_user_provider
|
||||
else
|
||||
{
|
||||
$this->_config = array(
|
||||
"base_url" => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
|
||||
"providers" => e107::getPref('social_login', array())
|
||||
"base_url" => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
|
||||
"providers" => e107::getPref('social_login', array()),
|
||||
"debug_mode" => 'error',
|
||||
"debug_file" => e_LOG."hybridAuth.log"
|
||||
);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user