first
This commit is contained in:
commit
5aa7d034f7
3292 changed files with 465160 additions and 0 deletions
38
data/web/oauth/authorize.php
Executable file
38
data/web/oauth/authorize.php
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
|
||||
|
||||
if (!isset($_SESSION['mailcow_cc_role'])) {
|
||||
$_SESSION['oauth2_request'] = $_SERVER['REQUEST_URI'];
|
||||
header('Location: /?oauth');
|
||||
}
|
||||
|
||||
$request = OAuth2\Request::createFromGlobals();
|
||||
$response = new OAuth2\Response();
|
||||
|
||||
if (!$oauth2_server->validateAuthorizeRequest($request, $response)) {
|
||||
$response->send();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_POST['authorized'])) {
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
|
||||
|
||||
$template = 'oauth/authorize.twig';
|
||||
$template_data = [];
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// print the authorization code if the user has authorized your client
|
||||
$is_authorized = ($_POST['authorized'] == '1');
|
||||
$oauth2_server->handleAuthorizeRequest($request, $response, $is_authorized, $_SESSION['mailcow_cc_username']);
|
||||
if ($is_authorized) {
|
||||
unset($_SESSION['oauth2_request']);
|
||||
if ($GLOBALS['OAUTH2_FORGET_SESSION_AFTER_LOGIN'] === true) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
}
|
||||
header('Location: ' . $response->getHttpHeader('Location'));
|
||||
exit;
|
||||
}
|
||||
32
data/web/oauth/profile.php
Executable file
32
data/web/oauth/profile.php
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
|
||||
|
||||
if (!$oauth2_server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
|
||||
$oauth2_server->getResponse()->send();
|
||||
die;
|
||||
}
|
||||
$token = $oauth2_server->getAccessTokenData(OAuth2\Request::createFromGlobals());
|
||||
$stmt = $pdo->prepare("SELECT * FROM `mailbox` WHERE `username` = :username AND `active` = '1'");
|
||||
$stmt->execute(array(':username' => $token['user_id']));
|
||||
$mailbox = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!empty($mailbox)) {
|
||||
if ($token['scope'] == 'profile') {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array(
|
||||
'success' => true,
|
||||
'username' => $token['user_id'],
|
||||
'id' => $token['user_id'],
|
||||
'identifier' => $token['user_id'],
|
||||
'email' => (!empty($mailbox['username']) ? $mailbox['username'] : ''),
|
||||
'full_name' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
|
||||
'displayName' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
|
||||
'created' => (!empty($mailbox['created']) ? $mailbox['created'] : ''),
|
||||
'modified' => (!empty($mailbox['modified']) ? $mailbox['modified'] : ''),
|
||||
'active' => (!empty($mailbox['active']) ? $mailbox['active'] : ''),
|
||||
));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode(array(
|
||||
'success' => false
|
||||
));
|
||||
4
data/web/oauth/token.php
Executable file
4
data/web/oauth/token.php
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
|
||||
$request = OAuth2\Request::createFromGlobals();
|
||||
$oauth2_server->handleTokenRequest($request)->send();
|
||||
Loading…
Add table
Add a link
Reference in a new issue