-
Notifications
You must be signed in to change notification settings - Fork 14
/
login_button.php
64 lines (55 loc) · 2.25 KB
/
login_button.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Amazon Login - Login for WordPress
*
* @category Amazon
* @package Amazon_Login
* @copyright Copyright (c) 2015 Amazon.com
* @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
*/
defined('ABSPATH') or die('Access denied');
if(get_option('loginwithamazon_client_id') && get_option('loginwithamazon_client_id') != '') {
add_action('wp_enqueue_scripts', 'loginwithamazon_enqueue_script');
add_action('login_enqueue_scripts', 'loginwithamazon_enqueue_script');
add_action('wp_footer', 'loginwithamazon_add_footer_script');
add_action('login_footer', 'loginwithamazon_add_footer_script');
}
function loginwithamazon_enqueue_script() {
wp_enqueue_script('loginwithamazon', LOGINWITHAMAZON__PLUGIN_URL . 'add_login.js');
}
function loginwithamazon_add_footer_script() {
$popup = 'false';
if(!empty($_SERVER['HTTPS'])) {
$popup = 'true';
}
$csrf = LoginWithAmazonUtility::hmac($_SESSION[LoginWithAmazonUtility::$CSRF_AUTHENTICATOR_KEY]);
?>
<div id="amazon-root"></div>
<script type="text/javascript">
window.onAmazonLoginReady = function() {
amazon.Login.setClientId('<?php echo get_option('loginwithamazon_client_id'); ?>');
amazon.Login.setUseCookie(true);
<?php if(isset($_GET['loggedout']) && $_GET['loggedout'] == 'true'): ?>
amazon.Login.logout();
<?php endif; ?>
};
(function(d) {
var a = d.createElement('script'); a.type = 'text/javascript';
a.async = true; a.id = 'amazon-login-sdk';
a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
d.getElementById('amazon-root').appendChild(a);
})(document);
function activateLoginWithAmazonButtons(elementId) {
document.getElementById(elementId).onclick = function() {
var options = {
scope: 'profile',
state: '<?php echo $csrf; ?>',
popup: <?php echo $popup; ?>
};
amazon.Login.authorize(options, '<?php echo str_replace('http://', 'https://', site_url('wp-login.php')); ?>?amazonLogin=1');
return false;
};
}
</script>
<?php
}