-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-auth.php
More file actions
121 lines (99 loc) · 2.79 KB
/
custom-auth.php
File metadata and controls
121 lines (99 loc) · 2.79 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Plugin Name: CBOX Authentication
* Plugin URI: https://github.com/mlaa/cbox-auth
* Description: Augments the WordPress login process to verify credentials against an external RESTful API. Additionally uses that API to sync BuddyPress group memberships with an external source.
*
* @link https://github.com/mlaa/cbox-auth
* @package CustomAuth
*/
namespace MLA\Commons\Plugin\CustomAuth;
require_once plugin_dir_path( __FILE__ ) . 'includes/loader.php';
use MLA\Commons\Plugin\Logging\Logger;
/**
* Plugin Loader class
*
* @package CustomAuth
* @subpackage PluginLoader
*/
class PluginLoader extends Base {
/**
* Login form
*
* @var object
*/
private $login_form;
/**
* Login processor
*
* @var object
*/
private $login_procesor;
/**
* Dependency: MLAAPI
*
* @var object
*/
private $mla_api;
/**
* Dependency: Logger
*
* @var object
*/
private $logger;
/**
* Constructor
*/
function __construct() {
// Create logging interface.
$this->logger = new Logger( 'cbox-auth' );
$this->logger->createLog( 'cbox-auth' );
// Expect API credentials to be defined as constants.
$credentials = array(
'api_url' => CBOX_AUTH_API_URL,
'api_key' => CBOX_AUTH_API_KEY,
'api_secret' => CBOX_AUTH_API_SECRET,
);
// Create MLA API interface.
$http_driver = new CurlDriver( $credentials, $this->logger );
$this->mla_api = new MLAAPI( $http_driver, $this->logger );
// Hook into WP authentication.
$this->login_form = new LoginForm( $this->mla_api, $this->logger );
$this->login_processor = new LoginProcessor( $this->mla_api, $this->logger );
$this->inject_superglobals();
new GroupBehavior( $this->mla_api, $this->logger );
new MemberBehavior( $this->mla_api, $this->logger );
new ProfileFields();
// BuddyPress functionality should wait for BuddyPress.
$this->add_action( 'bp_include', $this, 'init_ui_changes' );
$this->run();
}
/**
* Make adjustments to WP and BP UI.
*/
public function init_ui_changes() {
}
/**
* Inject data from superglobals.
*/
public function inject_superglobals() {
$login_form_data = array(
'username' => $this->get_superglobal( INPUT_POST, 'username' ),
'password' => $this->get_superglobal( INPUT_POST, 'password' ),
'preferred' => $this->get_superglobal( INPUT_POST, 'preferred' ),
);
foreach ( $login_form_data as $key => $value ) {
$this->login_form->set_cache( $key, $value );
}
$login_processor_data = array(
'server_port' => $this->get_superglobal( INPUT_SERVER, 'SERVER_PORT' ),
'preferred' => $this->get_superglobal( INPUT_POST, 'preferred' ),
'accepted' => $this->get_superglobal( INPUT_POST, 'acceptance' ),
);
foreach ( $login_processor_data as $key => $value ) {
$this->login_processor->set_cache( $key, $value );
}
}
}
// GO!
new PluginLoader();