Selaa lähdekoodia

Basic PHP service with auth based on user category

Brendan Abolivier 7 vuotta sitten
vanhempi
commit
350a50155c
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 muutettua tiedostoa jossa 35 lisäystä ja 0 poistoa
  1. 35
    0
      service1/index.php

+ 35
- 0
service1/index.php Näytä tiedosto

@@ -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
+}