Skip to content

Commit

Permalink
Added OpenWeWorkProvider. Fixed w7corp/easywechat#2202
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Sep 24, 2021
1 parent b21bb75 commit fd130ca
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 176 deletions.
48 changes: 0 additions & 48 deletions .php_cs

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"require-dev": {
"mockery/mockery": "~1.2",
"phpunit/phpunit": "~9.0"
"phpunit/phpunit": "~9.0",
"friendsofphp/php-cs-fixer": "^3.0"
},
"license": "MIT",
"authors": [
Expand All @@ -36,8 +37,8 @@
}
],
"scripts": {
"check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi",
"fix-style": "php-cs-fixer fix --using-cache=no --config=.php_cs --ansi",
"check-style": "php-cs-fixer fix --using-cache=no --diff --dry-run --ansi",
"fix-style": "php-cs-fixer fix --using-cache=no --ansi",
"test": "vendor/bin/phpunit --colors=always"
}
}
1 change: 0 additions & 1 deletion src/Exceptions/Feishu/InvalidTicketException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
*/
class InvalidTicketException extends Exception
{

}
36 changes: 18 additions & 18 deletions src/Providers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ abstract class Base implements ProviderInterface
{
public const NAME = null;

protected ?string $state = null;
protected ?string $state = null;
protected Config $config;
protected ?string $redirectUrl;
protected array $parameters = [];
protected array $scopes = [];
protected string $scopeSeparator = ',';
protected array $parameters = [];
protected array $scopes = [];
protected string $scopeSeparator = ',';
protected GuzzleClient $httpClient;
protected array $guzzleOptions = [];
protected int $encodingType = PHP_QUERY_RFC1738;
protected string $expiresInKey = 'expires_in';
protected string $accessTokenKey = 'access_token';
protected array $guzzleOptions = [];
protected int $encodingType = PHP_QUERY_RFC1738;
protected string $expiresInKey = 'expires_in';
protected string $accessTokenKey = 'access_token';
protected string $refreshTokenKey = 'refresh_token';

public function __construct(array $config)
Expand All @@ -34,7 +34,7 @@ public function __construct(array $config)
// set scopes
if ($this->config->has('scopes') && is_array($this->config->get('scopes'))) {
$this->scopes = $this->getConfig()->get('scopes');
} else if ($this->config->has('scope') && is_string($this->getConfig()->get('scope'))) {
} elseif ($this->config->has('scope') && is_string($this->getConfig()->get('scope'))) {
$this->scopes = array($this->getConfig()->get('scope'));
}

Expand Down Expand Up @@ -124,7 +124,7 @@ public function tokenFromCode(string $code): array
$this->getTokenUrl(),
[
'form_params' => $this->getTokenFields($code),
'headers' => [
'headers' => [
'Accept' => 'application/json',
],
]
Expand Down Expand Up @@ -259,10 +259,10 @@ protected function formatScopes(array $scopes, $scopeSeparator): string
protected function getTokenFields(string $code): array
{
return [
'client_id' => $this->getClientId(),
'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'code' => $code,
'redirect_uri' => $this->redirectUrl,
'code' => $code,
'redirect_uri' => $this->redirectUrl,
];
}

Expand All @@ -282,9 +282,9 @@ protected function getCodeFields(): array
{
$fields = array_merge(
[
'client_id' => $this->getClientId(),
'redirect_uri' => $this->redirectUrl,
'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
'client_id' => $this->getClientId(),
'redirect_uri' => $this->redirectUrl,
'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
'response_type' => 'code',
],
$this->parameters
Expand Down Expand Up @@ -325,9 +325,9 @@ protected function normalizeAccessTokenResponse($response): array
}

return $response + [
'access_token' => $response[$this->accessTokenKey],
'access_token' => $response[$this->accessTokenKey],
'refresh_token' => $response[$this->refreshTokenKey] ?? null,
'expires_in' => \intval($response[$this->expiresInKey] ?? 0),
'expires_in' => \intval($response[$this->expiresInKey] ?? 0),
];
}
}
23 changes: 1 addition & 22 deletions src/Providers/DouYin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ protected function getAuthUrl(): string
return $this->buildAuthUrlFromBase($this->baseUrl . '/platform/oauth/connect/');
}

/**
* @return array
*/
public function getCodeFields(): array
{
return [
Expand Down Expand Up @@ -68,12 +65,7 @@ public function tokenFromCode($code): array
return $this->normalizeAccessTokenResponse($body['data']);
}

/**
* @param string $code
*
* @return array
*/
protected function getTokenFields($code): array
protected function getTokenFields(string $code): array
{
return [
'client_key' => $this->getClientId(),
Expand All @@ -83,14 +75,6 @@ protected function getTokenFields($code): array
];
}

/**
* @param string $token
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
* @throws \GuzzleHttp\Exception\GuzzleException
*
*/
protected function getUserByToken(string $token): array
{
$userUrl = $this->baseUrl . '/oauth/userinfo/';
Expand All @@ -114,11 +98,6 @@ protected function getUserByToken(string $token): array
return $body['data'] ?? [];
}

/**
* @param array $user
*
* @return \Overtrue\Socialite\User
*/
protected function mapUserToObject(array $user): User
{
return new User(
Expand Down
28 changes: 14 additions & 14 deletions src/Providers/FeiShu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class FeiShu extends Base
{
public const NAME = 'feishu';
protected string $baseUrl = 'https://open.feishu.cn/open-apis';
protected string $expiresInKey = 'refresh_expires_in';
protected string $baseUrl = 'https://open.feishu.cn/open-apis';
protected string $expiresInKey = 'refresh_expires_in';
protected bool $isInternalApp = false;

public function __construct(array $config)
Expand All @@ -34,7 +34,7 @@ protected function getCodeFields(): array
{
return [
'redirect_uri' => $this->redirectUrl,
'app_id' => $this->getClientId(),
'app_id' => $this->getClientId(),
];
}

Expand Down Expand Up @@ -72,8 +72,8 @@ protected function getTokenFromCode(string $code): array
[
'json' => [
'app_access_token' => $this->config->get('app_access_token'),
'code' => $code,
'grant_type' => 'authorization_code',
'code' => $code,
'grant_type' => 'authorization_code',
],
]
);
Expand All @@ -98,7 +98,7 @@ protected function getUserByToken(string $token): array
$this->baseUrl . '/authen/v1/user_info',
[
'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token],
'query' => array_filter(
'query' => array_filter(
[
'user_access_token' => $token,
]
Expand All @@ -124,11 +124,11 @@ protected function mapUserToObject(array $user): User
{
return new User(
[
'id' => $user['user_id'] ?? null,
'name' => $user['name'] ?? null,
'id' => $user['user_id'] ?? null,
'name' => $user['name'] ?? null,
'nickname' => $user['name'] ?? null,
'avatar' => $user['avatar_url'] ?? null,
'email' => $user['email'] ?? null,
'avatar' => $user['avatar_url'] ?? null,
'email' => $user['email'] ?? null,
]
);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ protected function configAppAccessToken()
$url = $this->baseUrl . '/auth/v3/app_access_token/';
$params = [
'json' => [
'app_id' => $this->config->get('client_id'),
'app_id' => $this->config->get('client_id'),
'app_secret' => $this->config->get('client_secret'),
'app_ticket' => $this->config->get('app_ticket'),
],
Expand All @@ -178,7 +178,7 @@ protected function configAppAccessToken()
$url = $this->baseUrl . '/auth/v3/app_access_token/internal/';
$params = [
'json' => [
'app_id' => $this->config->get('client_id'),
'app_id' => $this->config->get('client_id'),
'app_secret' => $this->config->get('client_secret'),
],
];
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function configTenantAccessToken()
$url = $this->baseUrl . '/auth/v3/tenant_access_token/';
$params = [
'json' => [
'app_id' => $this->config->get('client_id'),
'app_id' => $this->config->get('client_id'),
'app_secret' => $this->config->get('client_secret'),
'app_ticket' => $this->config->get('app_ticket'),
],
Expand All @@ -218,7 +218,7 @@ protected function configTenantAccessToken()
$url = $this->baseUrl . '/auth/v3/tenant_access_token/internal/';
$params = [
'json' => [
'app_id' => $this->config->get('client_id'),
'app_id' => $this->config->get('client_id'),
'app_secret' => $this->config->get('client_secret'),
],
];
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class GitHub extends Base
{
public const NAME = 'github';
public const NAME = 'github';
protected array $scopes = ['read:user'];
protected string $scopeSeparator = ' ';
protected string $scopeSeparator = ' ';

protected function getAuthUrl(): string
{
Expand Down
Loading

0 comments on commit fd130ca

Please sign in to comment.