mirror of
https://github.com/1sept/oauth2-1sept.git
synced 2024-05-30 17:38:52 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb43f28d61 | |||
| 6d06db0d56 | |||
| e418024705 | |||
| eca6845e85 |
@@ -1,17 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||||
|
use League\OAuth2\Client\Provider\GenericProvider;
|
||||||
use League\OAuth2\Client\Token\AccessToken;
|
use League\OAuth2\Client\Token\AccessToken;
|
||||||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
|
||||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Провайдер данных Первого сентября
|
* Провайдер данных Первого сентября
|
||||||
*/
|
*/
|
||||||
class SeptemberFirstProvider extends AbstractProvider
|
class SeptemberFirstProvider extends GenericProvider
|
||||||
{
|
{
|
||||||
use BearerAuthorizationTrait;
|
use BearerAuthorizationTrait;
|
||||||
|
|
||||||
@@ -26,48 +28,41 @@ class SeptemberFirstProvider extends AbstractProvider
|
|||||||
const API_BASE = 'https://api.1sept.ru';
|
const API_BASE = 'https://api.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Версия API
|
* @var array Разрешения (scopes) по умолчанию
|
||||||
*/
|
*/
|
||||||
const API_VERSION = '2.0';
|
const SCOPES_DEFAULT = ['profile'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @var string Разделитель перечня запрашиваемых разрешений
|
||||||
*/
|
*/
|
||||||
public function getBaseAuthorizationUrl(): string
|
const SCOPES_SEPARATOR = ' ';
|
||||||
{
|
|
||||||
return static::AUTH_BASE.'/oauth/authorize';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @var string Путь авторизации
|
||||||
*/
|
*/
|
||||||
public function getBaseAccessTokenUrl(array $params): string
|
const AUTHORIZE_PATH = '/oauth/authorize';
|
||||||
{
|
|
||||||
return static::API_BASE.'/oauth/access_token';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @var string Путь получения токена
|
||||||
*/
|
*/
|
||||||
public function getResourceOwnerDetailsUrl(AccessToken $token): string
|
const ACCESS_TOKEN_PATH = '/oauth/access_token';
|
||||||
{
|
|
||||||
return static::API_BASE.'/'.static::API_VERSION.'/userinfo';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @var string Путь получения данных пользователя
|
||||||
*/
|
*/
|
||||||
public function getDefaultScopes(): array
|
const USERINFO_PATH = '/2.0/userinfo';
|
||||||
{
|
|
||||||
return ['profile'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function __construct(array $options = [], array $collaborators = [])
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
protected function getScopeSeparator(): string
|
|
||||||
{
|
{
|
||||||
return ' ';
|
$defaultOptions = [
|
||||||
|
'urlAuthorize' => static::AUTH_BASE.static::AUTHORIZE_PATH,
|
||||||
|
'urlAccessToken' => static::API_BASE.static::ACCESS_TOKEN_PATH,
|
||||||
|
'urlResourceOwnerDetails' => static::API_BASE.static::USERINFO_PATH,
|
||||||
|
'scopes' => static::SCOPES_DEFAULT,
|
||||||
|
'scopeSeparator' => static::SCOPES_SEPARATOR,
|
||||||
|
];
|
||||||
|
|
||||||
|
parent::__construct(array_merge($defaultOptions, $options), $collaborators);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,8 +70,8 @@ class SeptemberFirstProvider extends AbstractProvider
|
|||||||
*/
|
*/
|
||||||
protected function checkResponse(ResponseInterface $response, $data): void
|
protected function checkResponse(ResponseInterface $response, $data): void
|
||||||
{
|
{
|
||||||
if (!empty($data['error'])) {
|
if (! empty($data['error'])) {
|
||||||
throw new IdentityProviderException($data['error'].': '.$data['message'], null, $response);
|
throw new IdentityProviderException($data['error'].': '.$data['message'], 0, $response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
||||||
@@ -113,6 +115,16 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
return $this->getField('sex');
|
return $this->getField('sex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Регалии
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getRegalia(): string|null
|
||||||
|
{
|
||||||
|
return $this->getField('regalia');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Умер
|
* Умер
|
||||||
*
|
*
|
||||||
@@ -296,6 +308,18 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
return $this->getField('timezone');
|
return $this->getField('timezone');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID адреса
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
|
* @example 12345
|
||||||
|
*/
|
||||||
|
public function getAddressID(): ?int
|
||||||
|
{
|
||||||
|
$id = $this->getField('address.id');
|
||||||
|
return $id ? (int) $id : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID страны адреса
|
* ID страны адреса
|
||||||
*
|
*
|
||||||
@@ -306,7 +330,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
{
|
{
|
||||||
return $this->getField('address.country_id');
|
return $this->getField('address.country_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID региона страны адреса
|
* ID региона страны адреса
|
||||||
*
|
*
|
||||||
@@ -317,7 +341,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
{
|
{
|
||||||
return $this->getField('address.region_id');
|
return $this->getField('address.region_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Почтовый индекс
|
* Почтовый индекс
|
||||||
*
|
*
|
||||||
@@ -330,7 +354,106 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Почтовый адрес в строку
|
* Район
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Октябрьский район
|
||||||
|
*/
|
||||||
|
public function getAddressArea(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.area');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Город
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Муром
|
||||||
|
*/
|
||||||
|
public function getAddressCity(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.city');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Улица
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example ул. Профсоюзная
|
||||||
|
*/
|
||||||
|
public function getAddressStreet(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.street');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Здание, сооружение, дом, владение, объект незавершенного строительства
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example д. 5
|
||||||
|
*/
|
||||||
|
public function getAddressHouse(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.house');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Строение
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example стр. 5
|
||||||
|
*/
|
||||||
|
public function getAddressBuilding(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.building');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Помещение в пределах здания, сооружения (Квартира, офис, помещение и т.д.)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example кв. 1б | оф. 13 | помещ. 17
|
||||||
|
*/
|
||||||
|
public function getAddressFlat(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.flat');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* До востребования
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
* @example true
|
||||||
|
*/
|
||||||
|
public function isAddressGeneralDelivery(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getField('address.general_delivery');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Абонентский ящик (А/Я)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example а/я 123
|
||||||
|
*/
|
||||||
|
public function getAddressPostalBox(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.postal_box');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Организация по адресу
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Школа №5
|
||||||
|
*/
|
||||||
|
public function getAddressOrganization(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.organization');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Почтовый адрес в строку (без индекса)
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @example ул. Гагарина, д.5, кв. 21, Нижний Новгород
|
* @example ул. Гагарина, д.5, кв. 21, Нижний Новгород
|
||||||
|
|||||||
Reference in New Issue
Block a user