PoC of school digital workspace without a CAS, using Macaroons

index.php 592B

1234567891011121314151617181920212223242526272829303132333435
  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. echo "Access granted.\n<br />Welcome ".$m->getIdentifier()."!";
  24. } else {
  25. echo "Access denied. Service is restricted to teachers.";
  26. }