Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+16 -107
View File
@@ -11,7 +11,7 @@
namespace IPS\Login\Handler\OAuth2;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -59,10 +59,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
)
), NULL, NULL, NULL, 'login_real_name' )
),
parent::acpForm(),
array(
'allow_status_import' => new \IPS\Helpers\Form\YesNo( 'login_generic_allow_status_import', ( isset( $this->settings['allow_status_import'] ) ) ? $this->settings['allow_status_import'] : FALSE, FALSE )
)
parent::acpForm()
);
}
@@ -139,12 +136,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
'profile',
'email',
);
if ( \IPS\Settings::i()->profile_comments and isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] )
{
$return[] = 'https://www.googleapis.com/auth/plus.me';
}
return $return;
}
@@ -231,7 +223,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
*/
protected function authenticatedUserId( $accessToken )
{
return $this->_userData( $accessToken )['id'];
return $this->_userData( $accessToken )['sub'];
}
/**
@@ -245,7 +237,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
{
if ( isset( $this->settings['real_name'] ) and $this->settings['real_name'] )
{
return $this->_userData( $accessToken )['displayName'];
return $this->_userData( $accessToken )['name'];
}
return NULL;
}
@@ -259,11 +251,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
*/
protected function authenticatedEmail( $accessToken )
{
foreach ( $this->_userData( $accessToken )['emails'] as $email )
{
return $email['value'];
}
return NULL;
return $this->_userData( $accessToken )['email'];
}
/**
@@ -278,15 +266,15 @@ class _Google extends \IPS\Login\Handler\OAuth2
*/
public function userProfilePhoto( \IPS\Member $member )
{
if ( !( $link = $this->_link( $member ) ) )
if ( !( $link = $this->_link( $member ) ) or ( $link['token_expires'] and $link['token_expires'] < time() ) )
{
throw new \IPS\Login\Exception( NULL, \IPS\Login\Exception::INTERNAL_ERROR );
}
$userData = $this->_userData( $link['token_access_token'] );
if ( isset( $userData['image'] ) and !$userData['image']['isDefault'] )
if ( isset( $userData['picture'] ) and $userData['picture'] )
{
return \IPS\Http\Url::external( $userData['image']['url'] )->setQueryString( 'sz', NULL );
return \IPS\Http\Url::external( $userData['picture'] )->setQueryString( 'sz', NULL );
}
return NULL;
}
@@ -303,87 +291,14 @@ class _Google extends \IPS\Login\Handler\OAuth2
*/
public function userProfileName( \IPS\Member $member )
{
if ( !( $link = $this->_link( $member ) ) )
if ( !( $link = $this->_link( $member ) ) or ( $link['token_expires'] and $link['token_expires'] < time() ) )
{
throw new \IPS\Login\Exception( NULL, \IPS\Login\Exception::INTERNAL_ERROR );
}
return $this->_userData( $link['token_access_token'] )['displayName'];
return $this->_userData( $link['token_access_token'] )['name'];
}
/**
* Get user's cover photo
* May return NULL if server doesn't support this
*
* @param \IPS\Member $member Member
* @return \IPS\Http\Url|NULL
* @throws \IPS\Login\Exception The token is invalid and the user needs to reauthenticate
* @throws \DomainException General error where it is safe to show a message to the user
* @throws \RuntimeException Unexpected error from service
*/
public function userCoverPhoto( \IPS\Member $member )
{
if ( !( $link = $this->_link( $member ) ) )
{
throw new \IPS\Login\Exception( NULL, \IPS\Login\Exception::INTERNAL_ERROR );
}
$userData = $this->_userData( $link['token_access_token'] );
if ( isset( $userData['cover'] ) )
{
return \IPS\Http\Url::external( $userData['cover']['coverPhoto']['url'] )->setQueryString( 'sz', NULL );
}
return NULL;
}
/**
* Get user's statuses since a particular date
*
* @param \IPS\Member $member Member
* @param \IPS\DateTime|NULL $since Date/Time to get statuses since then, or NULL to get the latest one
* @return array
* @throws \IPS\Login\Exception The token is invalid and the user needs to reauthenticate
* @throws \DomainException General error where it is safe to show a message to the user
* @throws \RuntimeException Unexpected error from service
*/
public function userStatuses( \IPS\Member $member, \IPS\DateTime $since = NULL )
{
if ( !( $link = $this->_link( $member ) ) )
{
throw new \IPS\Login\Exception( NULL, \IPS\Login\Exception::INTERNAL_ERROR );
}
$response = \IPS\Http\Url::external( "https://www.googleapis.com/plus/v1/people/me/activities/public" )
->setQueryString( $since ? array() : array( 'maxResults' => 1 ) )
->request()
->setHeaders( array(
'Authorization' => "Bearer {$link['token_access_token']}"
) )
->get()
->decodeJson();
$return = array();
foreach ( $response['items'] as $statusData )
{
if ( $since and strtotime( $statusData['published'] ) < $since->getTimestamp() )
{
break;
}
if ( isset( $statusData['object']['content'] ) )
{
$status = \IPS\core\Statuses\Status::createItem( $member, $member->ip_address, new \IPS\DateTime( $statusData['published'] ) );
$status->content = $this->_parseStatusText( $member, nl2br( $statusData['object']['content'], FALSE ) );
$return[] = $status;
}
}
return $return;
}
/**
* Get link to user's remote profile
* May return NULL if server doesn't support this
@@ -397,7 +312,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
*/
public function userLink( $identifier, $username )
{
return \IPS\Http\Url::external( "https://plus.google.com/" . $identifier );
return NULL;
}
/**
@@ -418,7 +333,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
$return = array();
if ( ( !isset( $this->settings['update_email_changes'] ) or $this->settings['update_email_changes'] === 'optional' ) and ( in_array( 'email', $authorizedScopes ) or in_array( 'https://www.googleapis.com/auth/userinfo.email', $authorizedScopes ) ) )
if ( ( !isset( $this->settings['update_email_changes'] ) or $this->settings['update_email_changes'] === 'optional' ) and ( \in_array( 'email', $authorizedScopes ) or \in_array( 'https://www.googleapis.com/auth/userinfo.email', $authorizedScopes ) ) )
{
$return[] = 'email';
}
@@ -429,13 +344,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
}
$return[] = 'photo';
$return[] = 'cover';
if ( \IPS\Settings::i()->profile_comments and isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] and in_array( 'https://www.googleapis.com/auth/plus.me', $authorizedScopes ) )
{
$return[] = 'status';
}
return $return;
}
@@ -455,7 +364,7 @@ class _Google extends \IPS\Login\Handler\OAuth2
{
if ( !isset( $this->_cachedUserData[ $accessToken ] ) )
{
$response = \IPS\Http\Url::external( "https://www.googleapis.com/plus/v1/people/me" )
$response = \IPS\Http\Url::external( "https://www.googleapis.com/oauth2/v3/userinfo" )
->request()
->setHeaders( array(
'Authorization' => "Bearer {$accessToken}"