• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/helper/oauth/office365.php
  • Класс: BitrixMailHelperOAuthOffice365Interface
  • Вызов: Office365Interface::getGraphPrincipalName
private function getGraphPrincipalName(bool $isSwitchedAlready = false): string
	{
		$httpClient = new BitrixMainWebHttpClient();
		$httpClient->setHeader("Authorization", "Bearer " . $this->access_token);
		$jsonResponse = $httpClient->get($this->resource . static::VERSION . static::CONTACTS_URL);
		try
		{
			$decoded = BitrixMainWebJson::decode($jsonResponse);
			if (!empty($decoded['userPrincipalName']) && is_string($decoded['userPrincipalName']))
			{
				return $decoded['userPrincipalName'];
			}
			else if (!empty($decoded['error']) && !$isSwitchedAlready)
			{
				$this->refreshToGraphAccessToken();
				return $this->getGraphPrincipalName(true);
			}
		}
		catch (ArgumentException $e)
		{
			AddMessage2Log($e->getMessage(), 'mail', 2, true);
		}
		return '';
	}