forked from SocialConnect/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Sber class, SocialConnect#3.1.6-dev
- Loading branch information
1 parent
1108471
commit dea7f25
Showing
3 changed files
with
98 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SocialConnect\OAuth2\Provider; | ||
|
||
use SocialConnect\Common\ArrayHydrator; | ||
use SocialConnect\Provider\AccessTokenInterface; | ||
use SocialConnect\Common\Entity\User; | ||
|
||
class Sberbank extends \SocialConnect\OAuth2\AbstractProvider { | ||
const NAME = 'sber'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $requestHttpMethod = 'GET'; | ||
|
||
/** | ||
* Vk returns email inside AccessToken | ||
* | ||
* @var string|null | ||
*/ | ||
protected $email; | ||
|
||
public function getBaseUri() | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getAuthorizeUri() | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getRequestTokenUri() | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void | ||
{ | ||
if ($accessToken) { | ||
$query['access_token'] = $accessToken->getToken(); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIdentity(AccessTokenInterface $accessToken) | ||
{ | ||
$query = [ | ||
'v' => '5.100' | ||
]; | ||
|
||
$fields = $this->getArrayOption('identity.fields', []); | ||
if ($fields) { | ||
$query['fields'] = implode(',', $fields); | ||
} | ||
|
||
$response = $this->request('GET', 'method/users.get', $query, $accessToken); | ||
|
||
$hydrator = new ArrayHydrator([ | ||
'id' => 'id', | ||
'first_name' => 'firstname', | ||
'last_name' => 'lastname', | ||
'email' => 'email', | ||
'bdate' => static function ($value, User $user) { | ||
$user->setBirthday( | ||
new \DateTime($value) | ||
); | ||
}, | ||
'sex' => static function ($value, User $user) { | ||
$user->setSex($value === 1 ? User::SEX_FEMALE : User::SEX_MALE); | ||
}, | ||
'screen_name' => 'username', | ||
'photo_max_orig' => 'pictureURL', | ||
]); | ||
|
||
/** @var User $user */ | ||
$user = $hydrator->hydrate(new User(), $response['response'][0]); | ||
|
||
$user->email = $this->email; | ||
$user->emailVerified = true; | ||
|
||
return $user; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.