callback.php 976 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. use App\App\Bootstrap;
  4. use App\Security\EntraAuth;
  5. require dirname(__DIR__) . '/src/autoload.php';
  6. Bootstrap::init();
  7. $auth = new EntraAuth();
  8. // Entra reported an error (e.g. user cancelled or consent denied).
  9. if (isset($_GET['error'])) {
  10. Bootstrap::log('portal', 'Entra-Callback-Fehler: ' . (string) ($_GET['error'])
  11. . ' - ' . (string) ($_GET['error_description'] ?? ''));
  12. header('Location: ' . Bootstrap::url('portal/login.php?error=auth_failed'));
  13. exit;
  14. }
  15. $code = (string) ($_GET['code'] ?? '');
  16. $state = (string) ($_GET['state'] ?? '');
  17. if ($auth->handleCallback($code, $state)) {
  18. header('Location: ' . Bootstrap::url('portal/index.php'));
  19. exit;
  20. }
  21. // Distinguish "signed in but not allowlisted" is not possible here without extra state;
  22. // a generic failure keeps the flow simple and avoids leaking allowlist membership.
  23. header('Location: ' . Bootstrap::url('portal/login.php?error=auth_failed'));
  24. exit;