Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+20
-17
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Google Login Handler
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 20 Mar 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -31,33 +31,35 @@ class _Google extends LoginAbstract
|
||||
/**
|
||||
* Get Form
|
||||
*
|
||||
* @param string $url The URL for the login page
|
||||
* @param bool $ucp Is UCP? (as opposed to login form)
|
||||
* @param \IPS\Http\Url $url The URL for the login page
|
||||
* @param bool $ucp Is UCP? (as opposed to login form)
|
||||
* @param \IPS\Http\Url $destination The URL to redirect to after a successful login
|
||||
* @return string
|
||||
*/
|
||||
public function loginForm( $url, $ucp=FALSE )
|
||||
public function loginForm( \IPS\Http\Url $url, $ucp = FALSE, \IPS\Http\Url $destination = NULL )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'login', 'core', 'global' )->google( (string) $this->_googleSignInUrl( ( $ucp ? 'ucp' : \IPS\Dispatcher::i()->controllerLocation ), $ucp ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'login', 'core', 'global' )->google( (string) $this->_googleSignInUrl( ( $ucp ? 'ucp' : \IPS\Dispatcher::i()->controllerLocation ), $ucp, $destination ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sign in URL
|
||||
*
|
||||
* @param string $base Controls where the user is taken back to
|
||||
* @param bool $forcePrompt Force prompt? Will mean user is shown the Google site even if previously authenticated. Only to be used if a new refresh token is needed.
|
||||
* @param string $base Controls where the user is taken back to
|
||||
* @param bool $forcePrompt Force prompt? Will mean user is shown the Google site even if previously authenticated. Only to be used if a new refresh token is needed.
|
||||
* @param \IPS\Http\Url $destination The URL to redirect to after a successful login
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
protected function _googleSignInUrl( $base, $forcePrompt )
|
||||
protected function _googleSignInUrl( $base, $forcePrompt, \IPS\Http\Url $destination = NULL )
|
||||
{
|
||||
$params = array(
|
||||
'response_type' => 'code',
|
||||
'client_id' => $this->settings['client_id'],
|
||||
'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/google/auth.php', 'none' ),
|
||||
'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/google/auth.php', 'none', NULL, array(), \IPS\Settings::i()->logins_over_https ? \IPS\Http\Url::PROTOCOL_HTTPS : 0 ),
|
||||
'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
|
||||
'access_type' => 'offline',
|
||||
'state' => $base . '-' . \IPS\Session::i()->csrfKey
|
||||
'state' => $base . '-' . \IPS\Session::i()->csrfKey . '-' . ( $destination ? base64_encode( $destination ) : '' )
|
||||
);
|
||||
|
||||
|
||||
if ( $forcePrompt )
|
||||
{
|
||||
$params['approval_prompt'] = 'force';
|
||||
@@ -89,7 +91,7 @@ class _Google extends LoginAbstract
|
||||
'code' => \IPS\Request::i()->code,
|
||||
'client_id' => $this->settings['client_id'],
|
||||
'client_secret' => $this->settings['client_secret'],
|
||||
'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/google/auth.php', 'none' ),
|
||||
'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/google/auth.php', 'none', NULL, array(), \IPS\Settings::i()->logins_over_https ? \IPS\Http\Url::PROTOCOL_HTTPS : 0 ),
|
||||
'grant_type' => 'authorization_code',
|
||||
) )->decodeJson();
|
||||
if ( isset( $response['error'] ) or !isset( $response['access_token'] ) )
|
||||
@@ -98,8 +100,7 @@ class _Google extends LoginAbstract
|
||||
}
|
||||
|
||||
/* Get user data */
|
||||
$userData = \IPS\Http\Url::external( "https://www.googleapis.com/plus/v1/people/me?access_token={$response['access_token']}" )->request()->get()->decodeJson('id');
|
||||
$email = $userData = \IPS\Http\Url::external( "https://www.googleapis.com/oauth2/v1/userinfo?access_token={$response['access_token']}" )->request()->get()->decodeJson('email');
|
||||
$userData = \IPS\Http\Url::external( "https://www.googleapis.com/oauth2/v1/userinfo?access_token={$response['access_token']}" )->request()->get()->decodeJson();
|
||||
|
||||
/* Set member properties */
|
||||
$memberProperties = array( 'google_id' => $userData['id'] );
|
||||
@@ -193,12 +194,14 @@ class _Google extends LoginAbstract
|
||||
|
||||
if ( $response->httpResponseCode != 200 )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('login_3p_bad', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('login_handler_Google') ) ) ) );
|
||||
\IPS\Log::log( "Google oauth error: " . json_encode( $response ), 'google_oauth' );
|
||||
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack( 'login_3p_bad', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'login_handler_Google' ) ) ) ) );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('login_3p_bad', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('login_handler_Google') ) ) ) );
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack( 'login_3p_bad', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'login_handler_Google' ) ) ) ) );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user