Version 4.2.0
This commit is contained in:
1 parent
0dc2aee5ed
commit
96997ddd8e
2074 files changed
+125454
-55780
No files matched your search
+69
-19
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Facebook Login Handler
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 18 Mar 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Login;
|
||||
@@ -28,6 +27,11 @@ class _Facebook extends LoginAbstract
|
||||
*/
|
||||
public static $icon = 'facebook-square';
|
||||
|
||||
/**
|
||||
* @brief Logo
|
||||
*/
|
||||
public static $logo = 'Facebook';
|
||||
|
||||
/**
|
||||
* @brief Share Service
|
||||
*/
|
||||
@@ -44,20 +48,38 @@ class _Facebook extends LoginAbstract
|
||||
public function loginForm( \IPS\Http\Url $url, $ucp = FALSE, \IPS\Http\Url $destination = NULL )
|
||||
{
|
||||
$scope = 'email';
|
||||
$facebookUrl = "https://www.facebook.com/dialog/oauth";
|
||||
|
||||
if ( \IPS\Settings::i()->profile_comments )
|
||||
{
|
||||
if ( isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] )
|
||||
{
|
||||
$scope .= ',user_posts';
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $this->settings['autoshare'] ) and $this->settings['autoshare'] )
|
||||
{
|
||||
$scope .= ',publish_actions';
|
||||
if ( isset( $this->settings['autoshare'] ) and $this->settings['autoshare'] )
|
||||
{
|
||||
$scope .= ',publish_actions';
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->permissionRequest_Facebook ) )
|
||||
{
|
||||
$allowedExtra = array( 'pages_show_list', 'manage_pages', 'publish_pages' );
|
||||
|
||||
/* We need at least version 2.5 for this to work, 2.8 is latest */
|
||||
$facebookUrl = "https://www.facebook.com/v2.8/dialog/oauth";
|
||||
|
||||
foreach( explode( ',', \IPS\Request::i()->permissionRequest_Facebook ) as $new )
|
||||
{
|
||||
if ( in_array( trim( $new ), $allowedExtra ) )
|
||||
{
|
||||
$scope .= "," . $new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::external( "https://www.facebook.com/dialog/oauth" )->setQueryString( array(
|
||||
$url = \IPS\Http\Url::external( $facebookUrl )->setQueryString( array(
|
||||
'client_id' => $this->settings['app_id'],
|
||||
'scope' => $scope,
|
||||
'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/facebook/auth.php', 'none', NULL, array(), \IPS\Settings::i()->logins_over_https ? \IPS\Http\Url::PROTOCOL_HTTPS : 0 ),
|
||||
@@ -86,6 +108,13 @@ class _Facebook extends LoginAbstract
|
||||
{
|
||||
throw new \IPS\Login\Exception( 'CSRF_FAIL', \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
/* Check user approved */
|
||||
if( !isset( \IPS\Request::i()->code ) OR !\IPS\Request::i()->code )
|
||||
{
|
||||
throw new \IPS\Login\Exception( 'denied_oauth', \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
/* Get a token */
|
||||
try
|
||||
{
|
||||
@@ -102,16 +131,9 @@ class _Facebook extends LoginAbstract
|
||||
}
|
||||
|
||||
/* Now exchange it for a one that will last a bit longer in case the user wants to use syncing */
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/v2.8/oauth/access_token" )->request()->post( array(
|
||||
'grant_type' => 'fb_exchange_token',
|
||||
'client_id' => $this->settings['app_id'],
|
||||
'client_secret' => $this->settings['app_secret'],
|
||||
'fb_exchange_token' => $response['access_token']
|
||||
) )->decodeJson();
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
$response['access_token'] = $this->exchangeToken( $response['access_token'] );
|
||||
|
||||
if ( ! $response['access_token'] )
|
||||
{
|
||||
throw new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
@@ -137,6 +159,34 @@ class _Facebook extends LoginAbstract
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exchange a short lived token for a longer lived token
|
||||
*
|
||||
* @param string $shortLivedToken The short lived token to exchange for a long lived token
|
||||
* @return string
|
||||
*/
|
||||
public function exchangeToken( $shortLivedToken )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/v2.8/oauth/access_token" )->request()->post( array(
|
||||
'grant_type' => 'fb_exchange_token',
|
||||
'client_id' => $this->settings['app_id'],
|
||||
'client_secret' => $this->settings['app_secret'],
|
||||
'fb_exchange_token' => $shortLivedToken
|
||||
) )->decodeJson();
|
||||
|
||||
return $response['access_token'];
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'facebook' );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link Account
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user