mirror of
https://github.com/1sept/oauth2-1sept.git
synced 2024-05-30 17:38:52 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc1a2399f4 | |||
| 88fe261f43 | |||
| ddf2d1b6e4 |
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# @see http://EditorConfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[src/**]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
tab_width = 4
|
||||||
|
indent_style = space
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
@@ -6,6 +6,7 @@ namespace Sept\OAuth2\Client\Provider;
|
|||||||
|
|
||||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||||
use League\OAuth2\Client\Provider\GenericProvider;
|
use League\OAuth2\Client\Provider\GenericProvider;
|
||||||
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
||||||
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 Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@@ -28,7 +29,7 @@ class SeptemberFirstProvider extends GenericProvider
|
|||||||
const API_BASE = 'https://api.1sept.ru';
|
const API_BASE = 'https://api.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Разрешения (scopes) по умолчанию
|
* @var string[] Разрешения (scopes) по умолчанию
|
||||||
*/
|
*/
|
||||||
const SCOPES_DEFAULT = ['profile'];
|
const SCOPES_DEFAULT = ['profile'];
|
||||||
|
|
||||||
@@ -52,6 +53,12 @@ class SeptemberFirstProvider extends GenericProvider
|
|||||||
*/
|
*/
|
||||||
const USERINFO_PATH = '/2.0/userinfo';
|
const USERINFO_PATH = '/2.0/userinfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param mixed[] $options
|
||||||
|
* @param object[] $collaborators
|
||||||
|
*/
|
||||||
public function __construct(array $options = [], array $collaborators = [])
|
public function __construct(array $options = [], array $collaborators = [])
|
||||||
{
|
{
|
||||||
$defaultOptions = [
|
$defaultOptions = [
|
||||||
@@ -66,7 +73,13 @@ class SeptemberFirstProvider extends GenericProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Checks a provider response for errors.
|
||||||
|
*
|
||||||
|
* @param ResponseInterface $response
|
||||||
|
* @param mixed[]|string $data — Parsed response data
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws IdentityProviderException
|
||||||
*/
|
*/
|
||||||
protected function checkResponse(ResponseInterface $response, $data): void
|
protected function checkResponse(ResponseInterface $response, $data): void
|
||||||
{
|
{
|
||||||
@@ -76,7 +89,11 @@ class SeptemberFirstProvider extends GenericProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Generates a resource owner object from a successful resource owner details request.
|
||||||
|
*
|
||||||
|
* @param mixed[] $response
|
||||||
|
* @param AccessToken $token
|
||||||
|
* @return SeptemberFirstUser
|
||||||
*/
|
*/
|
||||||
protected function createResourceOwner(array $response, AccessToken $token): SeptemberFirstUser
|
protected function createResourceOwner(array $response, AccessToken $token): SeptemberFirstUser
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
const AVATAR_BASE = 'https://avatar.1sept.ru';
|
const AVATAR_BASE = 'https://avatar.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Массив с данными о пользователе
|
* @var mixed[] Массив с данными о пользователе
|
||||||
*/
|
*/
|
||||||
protected $data;
|
protected array $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $response
|
||||||
|
*/
|
||||||
public function __construct(array $response)
|
public function __construct(array $response)
|
||||||
{
|
{
|
||||||
$this->data = $response;
|
$this->data = $response;
|
||||||
@@ -26,7 +29,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Массив с данными о пользователе
|
* Массив с данными о пользователе
|
||||||
*
|
*
|
||||||
* @return array
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
@@ -58,7 +61,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Фамилия
|
* Фамилия
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getLastName(): ?string
|
public function getLastName(): ?string
|
||||||
{
|
{
|
||||||
@@ -68,7 +71,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Имя
|
* Имя
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getFirstName(): ?string
|
public function getFirstName(): ?string
|
||||||
{
|
{
|
||||||
@@ -78,7 +81,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Отчество
|
* Отчество
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getMiddleName(): ?string
|
public function getMiddleName(): ?string
|
||||||
{
|
{
|
||||||
@@ -152,20 +155,20 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
*/
|
*/
|
||||||
public function getBirthday(): ?\DateTime
|
public function getBirthday(): ?\DateTime
|
||||||
{
|
{
|
||||||
return !empty($this->data['birthday']) ? new \DateTime($this->data['birthday']) : null;
|
return ! empty($this->data['birthday']) ? new \DateTime($this->data['birthday']) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL аватарки (150x150)
|
* URL аватарки (150x150)
|
||||||
*
|
*
|
||||||
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
* @param bool $rejectDefaultAvatar
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*
|
*
|
||||||
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.jpeg?v=12345
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.jpeg?v=12345
|
||||||
*/
|
*/
|
||||||
public function getAvatarUrl(bool $addVersion = true): ?string
|
public function getAvatarUrl(bool $rejectDefaultAvatar = false): ?string
|
||||||
{
|
{
|
||||||
return $this->getField('avatar') . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
return ($rejectDefaultAvatar && $this->isDefaultAvatar()) ? null : $this->getField('avatar');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,8 +203,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* URL аватарки c максимальным размером
|
* URL аватарки c максимальным размером
|
||||||
*
|
*
|
||||||
* @param bool $useVersion Использовать версию аватарки для улучшенного кэширования
|
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
*
|
||||||
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.max.jpeg?v=12345
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.max.jpeg?v=12345
|
||||||
*/
|
*/
|
||||||
public function getAvatarMaxUrl(bool $addVersion = false): ?string
|
public function getAvatarMaxUrl(bool $addVersion = false): ?string
|
||||||
@@ -224,9 +228,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Является ли аватарка заглушкой
|
* Является ли аватарка заглушкой
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function isDefaultAvatar(): bool
|
public function isDefaultAvatar(): ?bool
|
||||||
{
|
{
|
||||||
return (bool) $this->getField('avatar_default');
|
return (bool) $this->getField('avatar_default');
|
||||||
}
|
}
|
||||||
@@ -260,7 +264,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Номера телефонов
|
* Номера телефонов
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array<int, array<string, string>>
|
||||||
* @example [
|
* @example [
|
||||||
* [
|
* [
|
||||||
* "canonical" => "+79161234567",
|
* "canonical" => "+79161234567",
|
||||||
@@ -279,7 +283,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* СНИЛС
|
* СНИЛС
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @example 123-123-123 56
|
* @example 123-456-789 01
|
||||||
*/
|
*/
|
||||||
public function getSnils(): ?string
|
public function getSnils(): ?string
|
||||||
{
|
{
|
||||||
@@ -533,9 +537,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* Элемент массива данных о пользователе
|
* Элемент массива данных о пользователе
|
||||||
*
|
*
|
||||||
* @param string $key Ключ поля (например: email или name.first — вложенность оформляется точкой)
|
* @param string $key Ключ поля (например: email или name.first — вложенность оформляется точкой)
|
||||||
* @return mixed|null
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function getField(string $key)
|
protected function getField(string $key): mixed
|
||||||
{
|
{
|
||||||
return static::getFieldFromArray($key, $this->data);
|
return static::getFieldFromArray($key, $this->data);
|
||||||
}
|
}
|
||||||
@@ -544,9 +548,10 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* Значение массива (многомерного)
|
* Значение массива (многомерного)
|
||||||
*
|
*
|
||||||
* @param string $key Ключ поля (например: `email` или `name.first` — вложенность оформляется точкой)
|
* @param string $key Ключ поля (например: `email` или `name.first` — вложенность оформляется точкой)
|
||||||
* @return mixed|null
|
* @param mixed[] $array
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function getFieldFromArray(string $key, ?array $array)
|
public static function getFieldFromArray(string $key, ?array $array): mixed
|
||||||
{
|
{
|
||||||
if (strpos($key, '.')) { // key.subKey.subSubKey
|
if (strpos($key, '.')) { // key.subKey.subSubKey
|
||||||
list ($key, $subKey) = explode('.', $key, 2);
|
list ($key, $subKey) = explode('.', $key, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user