PoC of school digital workspace without a CAS, using Macaroons

index.php 633B

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