Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_www/wp-content/plugins/his-login/lib/ |
Upload File : |
<?php
// https://www.cloudways.com/blog/add-facebook-login-in-php/
// ./composer.phar require league/oauth2-facebook
use League\OAuth2\Client\Token\AccessToken;
class authenticate_facebook extends his_authenticate {
public function __construct() {
parent::__construct();
$button = <<<'BLOCK'
<a href="/~/facebook-login" class="action-facebook _5h0c _5h0d" style="width: 400px; margin: 5px 0" role="button" tabindex="0">
<table class="uiGrid _51mz _5h0i _88va _5f0n" cellspacing="0" cellpadding="0"><tbody><tr class="_51mx"><td class="_51m-"><div class="_5h0j"><span class="_5h0k"><img class="img" src="https://static.xx.fbcdn.net/rsrc.php/v3/y3/r/U7MAWJlE6hZ.png" alt="" width="24" height="24"></span></div></td><td class="_51m- _51mw"><div class="_5h0s"><div class="_5h0o _8kto">Log in With Facebook</div></div></td></tr><tr class="_51mx"><td class="_51m-"><span class="_8jan"></span></td><td class="_51m-"></td></tr></tbody></table>
</a>
BLOCK;
$this->Name('Facebook')
->Head('')
->Button($button)
->onValueChange();
}
public function getValue($key = 'fb_client_id') {
return $this->values[$key] ?? '';
}
protected function onValueChange() {
//<script crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v17.0&appId={$id}&autoLogAppEvents=1" nonce="bFruQCAB"></script>
$id = rawurlencode($this->getValue()); // async defer
$head = <<<BLOCK
BLOCK;
$head .= <<<'BLOCK'
<style type="text/css">
._5h0d ._5h0i {
height: 40px;
}
._5h0i._88va {
background-color: #1877f2;
}
._5h0c {
background-color: transparent;
cursor: pointer;
display: inline-block;
vertical-align: top;
}
._5f0n {
table-layout: fixed;
width: 100%;
font-family: Helvetica, Arial, sans-serif;
line-height: 1.28;
-moz-text-size-adjust: none;
}
._5h0i {
border-radius: 4px;
color: #fff;
}
._5h0d ._88va ._5h0k {
margin: 8px 8px 8px 12px;
}
._5h0d ._8kto {
font-weight: bold;
padding-top: 1px;
}
._5h0c {
cursor: pointer;
}
._5h0i {
color: #fff;
}
._5h0d ._5h0o {
font-size: 16px;
margin-right: 12px;
}
._51mz {
border-collapse: collapse;
border-spacing: 0;
}
._5h0o {
border: none;
font-family: Helvetica, Arial, sans-serif;
letter-spacing: .25px;
overflow: hidden;
text-align: center;
text-overflow: clip;
white-space: nowrap;
}
._5h0d ._5h0i td:first-child, ._5h0d ._xvp._5h0i td:last-child {
width: 40px;
}
._5h0d ._88va ._5h0k {
margin: 8px 8px 8px 12px;
}
._5h0d ._5h0k {
height: 24px;
margin: 8px;
}
._5h0d ._5h0k img {
max-width: unset !important;
}
._5h0c ._5h0k {
float: left;
}
._5h0c ._5h0j {
white-space: nowrap;
}
._51mz ._51m-:first-child {
padding-left: 0;
}
._51mx:last-child > ._51m- {
padding-bottom: 0;
}
</style>
<script type="text/javascript">
function _fb_response(response) {
if (response.status == 'connected') {
document.location.href = '/~/facebook-auth' +
'?uid=' + encodeURIComponent( response.authResponse.userID) +
'&token=' + encodeURIComponent( response.authResponse.accessToken);
}
}
jQuery(function() {
let $form = jQuery('form.post-password-form');
if ($form.length) {
FB.getLoginStatus(function(response) {
_fb_response(response);
});
jQuery('.action-facebook').on('click', function(e) {
e.preventDefault()
FB.login(function(response) {
_fb_response(response);
}, {
scope: 'public_profile,email'
}
);
});
}
});
</script>
BLOCK;
$text = <<<BLOCK
<div id="fb-root"></div>
BLOCK;
$this->Head($head)
->Body($text);
}
public function FieldDefinition() {
return [
[
'name' => 'fb_client_id',
'caption' => 'App ID',
'type' => 'string',
], [
'name' => 'fb_secret',
'caption' => 'Secret',
'type' => 'string',
],
];
}
protected function _authorize($accessToken) {
$fb = new \League\OAuth2\Client\Provider\Facebook([
'clientId' => $this->getValue('fb_client_id'),
'clientSecret' => $this->getValue('fb_secret'),
// 'redirectUri' => 'https://example.com/callback-url',
'graphApiVersion' => 'v2.10',
]);
try {
$token = $fb->getLongLivedAccessToken($accessToken);
} catch (Exception $e) {
echo 'Failed to exchange the token: '.$e->getMessage(); // not a valid facebook login
exit;
}
$user = $fb->getResourceOwner($token);
if (empty($user->getEmail())) {
echo 'Fatal Error: You must have an email address associated with your facebook account';
exit;
}
return [
'id' => $user->getId(),
'email' => $user->getEmail(),
'name' => $user->getName(),
'picture' => $user->getPictureUrl(),
];
}
protected function _authorize_code($code) {
$site = get_site_url();
$fb = new \League\OAuth2\Client\Provider\Facebook([
'clientId' => $this->getValue('fb_client_id'),
'clientSecret' => $this->getValue('fb_secret'),
'redirectUri' => $site . '/~/facebook-auth',
'graphApiVersion' => 'v2.10',
]);
try {
$token = $fb->getAccessToken('authorization_code', [
'code' => $code,
]);
} catch (Exception $e) {
echo 'Failed to exchange the token: '.$e->getMessage(); // not a valid facebook login
exit;
}
$user = $fb->getResourceOwner($token);
if (empty($user->getEmail())) {
echo 'Fatal Error: You must have an email address associated with your facebook account';
exit;
}
return [
'id' => $user->getId(),
'email' => $user->getEmail(),
'name' => $user->getName(),
'picture' => $user->getPictureUrl(),
];
}
private function _generateLogin() {
$site = get_site_url();
$fb = new \League\OAuth2\Client\Provider\Facebook([
'clientId' => $this->getValue('fb_client_id'),
'clientSecret' => $this->getValue('fb_secret'),
// 'redirectUri' => 'https://example.com/callback-url',
'graphApiVersion' => 'v2.10',
]);
$permissions = ['email']; // Optional permissions
$redirectUrl = rawurlencode($site . '/~/facebook-auth');
$clientId = $this->getValue('fb_client_id');
$loginUrl = "https://www.facebook.com/v18.0/dialog/oauth?client_id={$clientId}&redirect_uri={$redirectUrl}&scope=email"; // &state={"{st=state123abc,ds=123456789}"}
header('Location: ' . $loginUrl);
}
public function onUrl($url) {
if ($url == '/~/facebook-auth' && !$this->isPost) {
session_start();
if (isset($_GET['code'])) {
$code = $_GET['code'];
return $this->_authorize_code($code);
} else {
$token = $_GET['token'];
return $this->_authorize($token);
}
} elseif ($url == '/~/facebook-login') {
session_start();
$this->_generateLogin();
session_write_close();
exit;
}
return NULL; // not intercepted
}
}
return new authenticate_facebook;
/*
FB.login(function(response) {
// handle the response
}, {scope: 'public_profile,email'});
FB.api('/v17.0/me', {fields: 'name,email'}, function(response2) {
console.log('Successful login for: ', response2);
});
GET https://graph.facebook.com/v11.0/oauth/access_token?
client_id={app-id} // Replace with your application’s ID
&redirect_uri={"https://www.domain.com/login"} // Must match the Redirect URI stated in the Authorization Request
&code_verifier={code-verifier} // Replace with generated code verifier
&code={authorization-code} // Replace with Authorization Code
*/