blob: 2bde21d369f4513c6b5bd827f79c4e9e4a04fab6 [file] [log] [blame]
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01001<?php
2require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
3
4if (!isset($_SESSION['mailcow_cc_role'])) {
5 $_SESSION['oauth2_request'] = $_SERVER['REQUEST_URI'];
6 header('Location: /?oauth');
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02007 exit;
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01008}
9
10$request = OAuth2\Request::createFromGlobals();
11$response = new OAuth2\Response();
12
13if (!$oauth2_server->validateAuthorizeRequest($request, $response)) {
14 $response->send();
15 exit;
16}
17
18if (!isset($_POST['authorized'])) {
19 require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
20
21 $template = 'oauth/authorize.twig';
22 $template_data = [];
23
24 require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
25 exit;
26}
27
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020028if (empty($_SESSION['mailcow_cc_username'])) {
29 header('Location: /?oauth');
30 exit;
31}
32
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010033// print the authorization code if the user has authorized your client
34$is_authorized = ($_POST['authorized'] == '1');
35$oauth2_server->handleAuthorizeRequest($request, $response, $is_authorized, $_SESSION['mailcow_cc_username']);
36if ($is_authorized) {
37 unset($_SESSION['oauth2_request']);
38 if ($GLOBALS['OAUTH2_FORGET_SESSION_AFTER_LOGIN'] === true) {
39 session_unset();
40 session_destroy();
41 }
42 header('Location: ' . $response->getHttpHeader('Location'));
43 exit;
44}