- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/helper/oauth/office365.php
- Класс: BitrixMailHelperOAuthOffice365Interface
- Вызов: Office365Interface::getCurrentUser
public function getCurrentUser()
{
if (empty($this->access_token))
{
return false;
}
$userPrincipalName = $this->getGraphPrincipalName();
$this->refreshToOutlookAccessToken();
$httpClient = new BitrixMainWebHttpClient();
$httpClient->setHeader("Authorization", "Bearer ". $this->access_token);
$result = $httpClient->get(static::OUTLOOK_RESOURCE . static::OUTLOOK_API_VERSION . static::CONTACTS_URL);
try
{
$result = BitrixMainWebJson::decode($result);
}
catch (ArgumentException $e)
{
AddMessage2Log($e->getMessage(), 'mail', 2, true);
$result = [];
}
if(isset($result['EmailAddress']))
{
$email = $result['EmailAddress'];
$emailIsIntended = false;
}
else
{
global $USER;
$email = $USER->GetEmail();
if(is_null($email))
{
$email = '';
}
$emailIsIntended = true;
}
return array_merge(
[
'email' => $email,
'emailIsIntended' => $emailIsIntended,
'userPrincipalName' => $userPrincipalName,
],
$this->getTokenData()
);
}