authorize.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  3. if (!isset($_SESSION['mailcow_cc_role'])) {
  4. $_SESSION['oauth2_request'] = $_SERVER['REQUEST_URI'];
  5. header('Location: /?oauth');
  6. }
  7. $request = OAuth2\Request::createFromGlobals();
  8. $response = new OAuth2\Response();
  9. if (!$oauth2_server->validateAuthorizeRequest($request, $response)) {
  10. $response->send();
  11. exit;
  12. }
  13. if (!isset($_POST['authorized'])) {
  14. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
  15. $template = 'oauth/authorize.twig';
  16. $template_data = [];
  17. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
  18. exit;
  19. }
  20. // print the authorization code if the user has authorized your client
  21. $is_authorized = ($_POST['authorized'] == '1');
  22. $oauth2_server->handleAuthorizeRequest($request, $response, $is_authorized, $_SESSION['mailcow_cc_username']);
  23. if ($is_authorized) {
  24. unset($_SESSION['oauth2_request']);
  25. if ($GLOBALS['OAUTH2_FORGET_SESSION_AFTER_LOGIN'] === true) {
  26. session_unset();
  27. session_destroy();
  28. }
  29. header('Location: ' . $response->getHttpHeader('Location'));
  30. exit;
  31. }