Skip to content

Commit

Permalink
Fixed #200
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 2, 2020
1 parent cb1c93c commit 765941f
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config implements ArrayAccess, \JsonSerializable
/**
* @var array
*/
protected $config;
protected array $config;

/**
* @param array $config
Expand Down
11 changes: 9 additions & 2 deletions src/Providers/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ protected function getTokenUrl(): string
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token): array
{
Expand Down Expand Up @@ -77,10 +78,12 @@ protected function mapUserToObject(array $user): User
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
*/
public function tokenFromCode(string $code): array
{
Expand All @@ -102,6 +105,10 @@ public function tokenFromCode(string $code): array
return $this->normalizeAccessTokenResponse($response['alipay_system_oauth_token_response']);
}

/**
* @return array
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
*/
protected function getCodeFields(): array
{
if (empty($this->redirectUrl)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Providers/Baidu.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ protected function getTokenFields($code): array
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token): array
{
Expand Down
3 changes: 2 additions & 1 deletion src/Providers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public function redirect(?string $redirectUrl = null): string
}

/**
* @param string $code
* @param string $code
*
* @return \Overtrue\Socialite\User
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userFromCode(string $code): User
{
Expand Down
5 changes: 3 additions & 2 deletions src/Providers/DingTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ protected function createSignature(int $time)
}

/**
* @param string $code
* @param string $code
*
* @return User
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @see https://ding-doc.dingtalk.com/doc#/personnal/tmudue
*/
public function userFromCode(string $code): User
Expand All @@ -110,7 +111,7 @@ public function userFromCode(string $code): User
);
$response = \json_decode($response->getBody()->getContents(), true);

if (0 != $response['errcode']) {
if (0 != $response['errcode'] ?? 1) {
throw new \InvalidArgumentException('You get error: ' . json_encode($response, JSON_UNESCAPED_UNICODE));
}

Expand Down
6 changes: 4 additions & 2 deletions src/Providers/DouYin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ protected function getTokenUrl(): string
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \GuzzleHttp\Exception\GuzzleException
*
*/
public function tokenFromCode($code): array
Expand Down Expand Up @@ -83,10 +84,11 @@ protected function getTokenFields($code): array
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
* @throws \GuzzleHttp\Exception\GuzzleException
*
*/
protected function getUserByToken(string $token): array
Expand Down
8 changes: 5 additions & 3 deletions src/Providers/Douban.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ protected function getTokenUrl(): string
}

/**
* @param string $token
* @param array|null $query
* @param string $token
* @param array|null $query
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token, ?array $query = []): array
{
Expand Down Expand Up @@ -65,10 +66,11 @@ protected function getTokenFields(string $code): array
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function tokenFromCode(string $code): array
{
Expand Down
14 changes: 8 additions & 6 deletions src/Providers/FeiShu.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@ protected function getTokenUrl(): string
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function tokenFromCode($code): array
public function tokenFromCode(string $code): array
{
return $this->normalizeAccessTokenResponse($this->getTokenFromCode($code));
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws AuthorizeFailedException
*
* @throws AuthorizeFailedException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getTokenFromCode(string $code): array
{
Expand All @@ -74,9 +75,10 @@ protected function getTokenFromCode(string $code): array
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token): array
{
Expand Down
7 changes: 4 additions & 3 deletions src/Providers/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ protected function getTokenUrl(): string
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token): array
{
Expand All @@ -43,11 +44,11 @@ protected function getUserByToken(string $token): array
}

/**
* @param string $token
* @param string $token
*
* @return string
*/
protected function getEmailByToken($token)
protected function getEmailByToken(string $token)
{
$emailsUrl = 'https://api.github.com/user/emails';

Expand Down
13 changes: 7 additions & 6 deletions src/Providers/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ protected function getTokenUrl(): string
}

/**
* @param string $code
*
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @param string $code
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
*/
public function tokenFromCode($code): array
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'body' => $this->getTokenFields($code),
'form_params' => $this->getTokenFields($code),
]);

return $this->normalizeAccessTokenResponse($response->getBody());
Expand All @@ -53,10 +53,11 @@ protected function getTokenFields($code): array
}

/**
* @param string $token
* @param array|null $query
* @param string $token
* @param array|null $query
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token, ?array $query = []): array
{
Expand Down
33 changes: 12 additions & 21 deletions src/Providers/Linkedin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ protected function getTokenFields($code): array
}

/**
* @param string $token
* @param array|null $query
* @param string $token
* @param array|null $query
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token, ?array $query = []): array
{
Expand All @@ -47,11 +48,12 @@ protected function getUserByToken(string $token, ?array $query = []): array
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getBasicProfile($token)
protected function getBasicProfile(string $token)
{
$url = 'https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))';

Expand All @@ -66,11 +68,12 @@ protected function getBasicProfile($token)
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getEmailAddress($token)
protected function getEmailAddress(string $token)
{
$url = 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))';

Expand All @@ -91,18 +94,18 @@ protected function getEmailAddress($token)
*/
protected function mapUserToObject(array $user): User
{
$preferredLocale = $user['firstName.preferredLocale.language'] ?? null.'_'.$user['firstName.preferredLocale.country'] ?? null;
$preferredLocale = ($user['firstName.preferredLocale.language'] ?? null).'_'.($user['firstName.preferredLocale.country']) ?? null;
$firstName = $user['firstName.localized.'.$preferredLocale] ?? null;
$lastName = $user['lastName.localized.'.$preferredLocale] ?? null;
$name = $firstName.' '.$lastName;

$images = $user['profilePicture.displayImage~.elements'] ?? [];
$avatars = array_filter($images, function ($image) {
return $image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] === 100;
return ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 100;
});
$avatar = array_shift($avatars);
$originalAvatars = array_filter($images, function ($image) {
return $image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] === 800;
return ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 800;
});
$originalAvatar = array_shift($originalAvatars);

Expand All @@ -115,16 +118,4 @@ protected function mapUserToObject(array $user): User
'avatar_original' => $originalAvatar['identifiers.0.identifier'] ?? null,
]);
}

/**
* @param array $fields
*
* @return $this
*/
public function fields(array $fields)
{
$this->fields = $fields;

return $this;
}
}
5 changes: 3 additions & 2 deletions src/Providers/Outlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ protected function getTokenUrl(): string
}

/**
* @param string $token
* @param array|null $query
* @param string $token
* @param array|null $query
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function getUserByToken(string $token, ?array $query = []): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/QCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ protected function getSecretKey(): string
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
*/
public function TokenFromCode($code): array
public function TokenFromCode(string $code): array
{
$response = $this->performRequest(
'GET',
Expand Down
11 changes: 6 additions & 5 deletions src/Providers/QQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ protected function getTokenUrl(): string
}

/**
* @param string $code
* @param string $code
*
* @return array
*/
protected function getTokenFields($code): array
protected function getTokenFields(string $code): array
{
return parent::getTokenFields($code) + [
'grant_type' => 'authorization_code',
];
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException|\GuzzleHttp\Exception\GuzzleException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function tokenFromCode($code): array
public function tokenFromCode(string $code): array
{
$response = $this->getHttpClient()->get($this->getTokenUrl(), [
'query' => $this->getTokenFields($code),
Expand Down
Loading

0 comments on commit 765941f

Please sign in to comment.