Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -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;
|
||||
@@ -131,9 +131,9 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
protected function scopesToRequest( $additional=NULL )
|
||||
{
|
||||
return array(
|
||||
'wl.signin',
|
||||
'wl.emails',
|
||||
'wl.offline_access'
|
||||
'openid',
|
||||
'User.Read',
|
||||
'offline_access'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
*/
|
||||
protected function authorizationEndpoint( \IPS\Login $login )
|
||||
{
|
||||
return \IPS\Http\Url::external('https://login.live.com/oauth20_authorize.srf');
|
||||
return \IPS\Http\Url::external('https://login.microsoftonline.com/common/oauth2/v2.0/authorize');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +155,7 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
*/
|
||||
protected function tokenEndpoint()
|
||||
{
|
||||
return \IPS\Http\Url::external('https://login.live.com/oauth20_token.srf');
|
||||
return \IPS\Http\Url::external('https://login.microsoftonline.com/common/oauth2/v2.0/token');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +194,7 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
if ( isset( $this->settings['real_name'] ) and $this->settings['real_name'] )
|
||||
{
|
||||
return $this->_userData( $accessToken )['name'];
|
||||
return $this->_userData( $accessToken )['displayName'];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -208,34 +208,9 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
*/
|
||||
protected function authenticatedEmail( $accessToken )
|
||||
{
|
||||
return $this->_userData( $accessToken )['emails']['preferred'];
|
||||
return $this->_userData( $accessToken )['userPrincipalName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user's profile 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 userProfilePhoto( \IPS\Member $member )
|
||||
{
|
||||
if ( !( $link = $this->_link( $member ) ) )
|
||||
{
|
||||
throw new \IPS\Login\Exception( NULL, \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::external( "https://apis.live.net/v5.0/me/picture" )->setQueryString( 'access_token', $link['token_access_token'] );
|
||||
if ( $url->request()->head()->httpResponseCode == 404 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get user's profile name
|
||||
* May return NULL if server doesn't support this
|
||||
@@ -248,12 +223,12 @@ class _Microsoft 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'] )['name'];
|
||||
return $this->_userData( $link['token_access_token'] )['displayName'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,9 +251,7 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
$return[] = 'name';
|
||||
}
|
||||
|
||||
$return[] = 'photo';
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -298,14 +271,14 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
if ( !isset( $this->_cachedUserData[ $accessToken ] ) )
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://apis.live.net/v5.0/me" )
|
||||
$response = \IPS\Http\Url::external( "https://graph.microsoft.com/v1.0/me" )
|
||||
->request()
|
||||
->setHeaders( array(
|
||||
'Authorization' => "Bearer {$accessToken}"
|
||||
) )
|
||||
->get()
|
||||
->decodeJson();
|
||||
|
||||
|
||||
if ( isset( $response['error'] ) )
|
||||
{
|
||||
throw new \IPS\Login\Exception( $response['error']['message'], \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
@@ -313,6 +286,7 @@ class _Microsoft extends \IPS\Login\Handler\OAuth2
|
||||
|
||||
$this->_cachedUserData[ $accessToken ] = $response;
|
||||
}
|
||||
|
||||
return $this->_cachedUserData[ $accessToken ];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user