|
@@ -76,14 +76,16 @@ class auth_plugin_macaroons extends auth_plugin_base {
|
76
|
76
|
*/
|
77
|
77
|
function loginpage_hook() {
|
78
|
78
|
global $DB, $login, $CFG;
|
79
|
|
- $placeholders[0] = "/{{firstname}}/";
|
80
|
|
- $placeholders[1] = "/{{lastname}}/";
|
|
79
|
+
|
81
|
80
|
if(!empty($_COOKIE[$this->config->cookie_name])) {
|
82
|
81
|
try {
|
|
82
|
+ // Getting the macaroon from the cookie it's stored in
|
83
|
83
|
$m = Macaroon::deserialize($_COOKIE[$this->config->cookie_name]);
|
84
|
84
|
|
85
|
85
|
$callbacks = array();
|
86
|
86
|
|
|
87
|
+ // Defining the callbacks according to the plugin's configuration
|
|
88
|
+ // in order to check all caveats
|
87
|
89
|
if(!empty($this->config->caveat1_condition)) {
|
88
|
90
|
array_push($callbacks, function($a) {
|
89
|
91
|
return !strcmp($a, $this->config->caveat1_condition);
|
|
@@ -103,6 +105,8 @@ class auth_plugin_macaroons extends auth_plugin_base {
|
103
|
105
|
$v = new Verifier();
|
104
|
106
|
$v->setCallbacks($callbacks);
|
105
|
107
|
|
|
108
|
+ // This will check both the signature and the caveats. Both must be OK
|
|
109
|
+ // in order to continue
|
106
|
110
|
if($v->verify($m, $this->config->secret)) {
|
107
|
111
|
$identifier = explode(";", $m->getIdentifier());
|
108
|
112
|
$parsed_id = $this->parse_identifier($identifier);
|
|
@@ -111,6 +115,10 @@ class auth_plugin_macaroons extends auth_plugin_base {
|
111
|
115
|
} else {
|
112
|
116
|
$login = $parsed_id["username"];
|
113
|
117
|
}
|
|
118
|
+
|
|
119
|
+ // Checking if the user is accepted by at least one authentication
|
|
120
|
+ // method (ours should accept it), and retrieving the user's class
|
|
121
|
+ // This will create the user if it doesn't exist
|
114
|
122
|
$user = authenticate_user_login($login, null);
|
115
|
123
|
|
116
|
124
|
if($user) {
|
|
@@ -120,17 +128,25 @@ class auth_plugin_macaroons extends auth_plugin_base {
|
120
|
128
|
if(!empty($parsed_id["lastname"])) {
|
121
|
129
|
$user->lastname = $parsed_id["lastname"];
|
122
|
130
|
}
|
|
131
|
+
|
|
132
|
+ // Generating the user's e-mail address according
|
|
133
|
+ // to its name and the config's template
|
|
134
|
+ $placeholders[0] = "/{{firstname}}/";
|
|
135
|
+ $placeholders[1] = "/{{lastname}}/";
|
123
|
136
|
$user->email = preg_replace($placeholders, [
|
124
|
137
|
$parsed_id["firstname"],
|
125
|
138
|
$parsed_id["lastname"]
|
126
|
139
|
], $this->config->email_config);
|
|
140
|
+ // Register modifications in DB, and logging the user in
|
127
|
141
|
$DB->update_record('user', $user);
|
128
|
|
- var_dump($user);
|
129
|
142
|
complete_user_login($user);
|
|
143
|
+ // Authentication is OK, let's redirect the user out of
|
|
144
|
+ // the login page
|
130
|
145
|
redirect($CFG->wwwroot);
|
131
|
146
|
}
|
132
|
147
|
}
|
133
|
148
|
} catch(Exception $e) {
|
|
149
|
+ // We currently do nothing with exceptions
|
134
|
150
|
$message = $e->getMessage();
|
135
|
151
|
}
|
136
|
152
|
}
|
|
@@ -155,6 +171,7 @@ class auth_plugin_macaroons extends auth_plugin_base {
|
155
|
171
|
return $parsed_id;
|
156
|
172
|
}
|
157
|
173
|
|
|
174
|
+ // Filling the fields
|
158
|
175
|
if(is_numeric($index = array_search("{{username}}", $placeholders))) {
|
159
|
176
|
$parsed_id["username"] = $identifier[$index];
|
160
|
177
|
}
|