git subrepo clone https://github.com/mailcow/mailcow-dockerized.git mailcow/src/mailcow-dockerized

subrepo: subdir:   "mailcow/src/mailcow-dockerized"
  merged:   "a832becb"
upstream: origin:   "https://github.com/mailcow/mailcow-dockerized.git"
  branch:   "master"
  commit:   "a832becb"
git-subrepo: version:  "0.4.3"
  origin:   "???"
  commit:   "???"
Change-Id: If5be2d621a211e164c9b6577adaa7884449f16b5
diff --git a/mailcow/src/mailcow-dockerized/data/web/oauth/profile.php b/mailcow/src/mailcow-dockerized/data/web/oauth/profile.php
new file mode 100644
index 0000000..4364c19
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/web/oauth/profile.php
@@ -0,0 +1,31 @@
+<?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'],

+      '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

+));