blob: 4364c19078e4748929c8125960ab2aaa57b38ae4 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
3
4if (!$oauth2_server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
5 $oauth2_server->getResponse()->send();
6 die;
7}
8$token = $oauth2_server->getAccessTokenData(OAuth2\Request::createFromGlobals());
9$stmt = $pdo->prepare("SELECT * FROM `mailbox` WHERE `username` = :username AND `active` = '1'");
10$stmt->execute(array(':username' => $token['user_id']));
11$mailbox = $stmt->fetch(PDO::FETCH_ASSOC);
12if (!empty($mailbox)) {
13 if ($token['scope'] == 'profile') {
14 header('Content-Type: application/json');
15 echo json_encode(array(
16 'success' => true,
17 'username' => $token['user_id'],
18 'identifier' => $token['user_id'],
19 'email' => (!empty($mailbox['username']) ? $mailbox['username'] : ''),
20 'full_name' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
21 'displayName' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
22 'created' => (!empty($mailbox['created']) ? $mailbox['created'] : ''),
23 'modified' => (!empty($mailbox['modified']) ? $mailbox['modified'] : ''),
24 'active' => (!empty($mailbox['active']) ? $mailbox['active'] : ''),
25 ));
26 exit;
27 }
28}
29echo json_encode(array(
30 'success' => false
31));