|
@@ -0,0 +1,35 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+require_once('vendor/autoload.php');
|
|
4
|
+
|
|
5
|
+use Macaroons\Macaroon;
|
|
6
|
+use Macaroons\Verifier;
|
|
7
|
+
|
|
8
|
+if(!isset($_COOKIE['das-macaroon'])) {
|
|
9
|
+ echo "Not logged in";
|
|
10
|
+ exit();
|
|
11
|
+}
|
|
12
|
+
|
|
13
|
+$serialised = $_COOKIE['das-macaroon'];
|
|
14
|
+
|
|
15
|
+$m = Macaroon::deserialize($serialised);
|
|
16
|
+$v = new Verifier();
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+$v->setCallbacks([
|
|
20
|
+ function($a) {
|
|
21
|
+ return !strcmp($a, "status = teacher");
|
|
22
|
+ }
|
|
23
|
+]);
|
|
24
|
+
|
|
25
|
+try {
|
|
26
|
+ $bool = $v->verify($m, 'pocsecret');
|
|
27
|
+} catch(Exception $e) {
|
|
28
|
+ $bool = false;
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+if($bool) {
|
|
32
|
+ echo "Access granted.\n<br />Welcome ".$m->getIdentifier()."!";
|
|
33
|
+} else {
|
|
34
|
+ echo "Access denied. Service is restricted to teachers.";
|
|
35
|
+}
|