提交的内容

This commit is contained in:
2025-05-12 15:45:02 +08:00
parent 629c4750da
commit b48c692775
3043 changed files with 34732 additions and 60810 deletions

0
vendor/overtrue/socialite/.github/FUNDING.yml vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/.github/dependabot.yml vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/.github/workflows/lint.yml vendored Executable file → Normal file
View File

25
vendor/overtrue/socialite/.github/workflows/test.yml vendored Executable file → Normal file
View File

@ -11,18 +11,21 @@ jobs:
php_version:
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
perfer:
- stable
- lowest
steps:
- uses: actions/checkout@v3
- run: composer validate --strict
- run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
id: composer-cache
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: dependencies-caches-php-${{ hashFiles('**/composer.lock') }}
restore-keys: dependencies-caches-php-
- run: composer update --prefer-dist --no-interaction --no-suggest --prefer-${{ matrix.perfer }}
- run: ./vendor/bin/phpunit
- uses: actions/checkout@v3
- run: composer validate --strict
- run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
id: composer-cache
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: dependencies-caches-php-${{ hashFiles('**/composer.lock') }}
restore-keys: dependencies-caches-php-
- run: composer update --prefer-dist --no-interaction --no-suggest --prefer-${{ matrix.perfer }}
- run: ./vendor/bin/phpunit

0
vendor/overtrue/socialite/.gitignore vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/LICENSE vendored Executable file → Normal file
View File

115
vendor/overtrue/socialite/README.md vendored Executable file → Normal file
View File

@ -12,19 +12,17 @@ Socialite 是一个 [OAuth2](https://oauth.net/2/) 认证工具。 它的灵感
如果你喜欢我的项目并想支持我,[点击这里 :heart:](https://github.com/sponsors/overtrue)
# 版本要求
## 版本要求
```
PHP >= 8.0.2
```
# 安装
## 安装
```shell
$ composer require "overtrue/socialite" -vvv
composer require "overtrue/socialite" -vvv
```
# 使用指南
## 使用指南
用户只需要创建相应配置变量,然后通过工具为各个平台创建认证应用,并轻松获取该平台的 access_token 和用户相关信息。工具实现逻辑详见参照各大平台 OAuth2 文档。
@ -56,7 +54,7 @@ $socialite = new SocialiteManager($config);
$url = $socialite->create('github')->redirect();
return redirect($url);
return redirect($url);
```
`callback.php`:
@ -117,20 +115,20 @@ $config = [
$config = [
// 为 github 应用起别名为 foo
'foo' => [
'provider' => 'github', // <-- provider name
'client_id' => 'your-app-id',
'provider' => 'github', // <-- provider name
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
'redirect' => 'http://localhost/socialite/callback.php',
'redirect' => 'http://localhost/socialite/callback.php',
],
// 另外一个名字叫做 bar 的 github 应用
'bar' => [
'provider' => 'github', // <-- provider name
'client_id' => 'your-app-id',
'provider' => 'github', // <-- provider name
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
'redirect' => 'http://localhost/socialite/callback.php',
'redirect' => 'http://localhost/socialite/callback.php',
],
//...
];
@ -159,7 +157,7 @@ $config = [
];
$socialite = new SocialiteManager($config);
$socialite->extend('myprovider', function(array $config) {
return new MyCustomProvider($config);
});
@ -167,12 +165,14 @@ $socialite->extend('myprovider', function(array $config) {
$app = $socialite->create('foo');
```
2. 使用服务提供类
1. 使用服务提供类
>👋🏻 你的自定义服务提供类必须实现`Overtrue\Socialite\Contracts\ProviderInterface` 接口
> [!IMPORTANT]
>
> 👋🏻 你的自定义服务提供类必须实现 `Overtrue\Socialite\Contracts\ProviderInterface` 接口
```php
class MyCustomProvider implements \Overtrue\Socialite\Contracts\ProviderInterface
class MyCustomProvider implements \Overtrue\Socialite\Contracts\ProviderInterface
{
//...
}
@ -183,10 +183,10 @@ class MyCustomProvider implements \Overtrue\Socialite\Contracts\ProviderInterfac
```php
$config = [
'foo' => [
'provider' => MyCustomProvider::class, // <-- 类名
'client_id' => 'your-app-id',
'provider' => MyCustomProvider::class, // <-- 类名
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
'redirect' => 'http://localhost/socialite/callback.php',
'redirect' => 'http://localhost/socialite/callback.php',
],
];
@ -194,8 +194,6 @@ $socialite = new SocialiteManager($config);
$app = $socialite->create('foo');
```
## 平台
不同的平台有不同的配置方法,为了确保工具的正常运行,所以请确保你所使用的平台的配置都是如期设置的。
@ -208,8 +206,8 @@ $app = $socialite->create('foo');
$config = [
'alipay' => [
// 这个键名还能像官方文档那样叫做 'app_id'
'client_id' => 'your-app-id',
'client_id' => 'your-app-id',
// 请根据官方文档,在官方管理后台配置 RSA2
// 注意: 这是你自己的私钥
// 注意: 不允许私钥内容有其他字符
@ -219,7 +217,7 @@ $config = [
// 确保这里的值与你在服务后台绑定的地址值一致
// 这个键名还能像官方文档那样叫做 'redirect_url'
'redirect' => 'http://localhost/socialite/callback.php',
// 沙箱模式接入地址见 https://opendocs.alipay.com/open/220/105337#%E5%85%B3%E4%BA%8E%E6%B2%99%E7%AE%B1
'sandbox' => false,
]
@ -252,7 +250,7 @@ $config = [
// or 'app_id'
'client_id' => 'your app id',
// or 'app_secret'
// or 'app_secret'
'client_secret' => 'your app secret',
// or 'redirect_url'
@ -332,7 +330,6 @@ $user = $socialite->create('xigua')->userFromCode('here is auth code');
$user = $socialite->create('xigua')->withOpenId('openId')->userFromToken('here is the access token');
```
### [百度](https://developer.baidu.com/wiki/index.php?title=docs/oauth)
其他配置没啥区别,在用法上,可以很轻易的选择重定向登录页面的模式,通过 `withDisplay()`
@ -361,7 +358,7 @@ $config = [
// or 'app_id'
'client_id' => 'your app id',
// or 'app_secret'
// or 'app_secret'
'client_secret' => 'your app secret',
// or 'redirect_url'
@ -391,7 +388,7 @@ $config = [
// or 'app_id'
'client_id' => 'your app id',
// or 'app_secret'
// or 'app_secret'
'client_secret' => 'your app secret',
// or 'redirect_url'
@ -413,7 +410,7 @@ $larkDriver->withDefaultMode()->withAppTicket('app_ticket')->userFromCode('here
### [淘宝](https://open.taobao.com/doc.htm?docId=102635&docType=1&source=search)
其他配置与其他平台的一样,你能选择你想要展示的重定向页面类型通过使用 `withView()`
其他配置与其他平台的一样,你能选择你想要展示的重定向页面类型通过使用 `withView()`
```php
$authUrl = $socialite->create('taobao')->withView('wap')->redirect();
@ -432,9 +429,9 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
[
'wechat' =>
[
'client_id' => 'client_id',
'client_id' => 'client_id',
'client_secret' => 'client_secret',
'redirect' => 'redirect-url',
'redirect' => 'redirect-url',
// 开放平台 - 第三方平台所需
'component' => [
@ -448,7 +445,6 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
...
```
### [Coding](https://coding.net/help/openapi#oauth)
您需要额外配置 `team_url` 为您的团队域名,例如:
@ -456,7 +452,7 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect();
```php
$config = [
'coding' => [
'team_url' => 'https://{your-team}.coding.net',
'team_url' => 'https://{your-team}.coding.net',
'client_id' => 'your app id',
'client_secret' => 'your app secret',
'redirect' => 'redirect URL',
@ -464,6 +460,23 @@ $config = [
];
```
### [PayPal](https://developer.paypal.com/docs/log-in-with-paypal/)
您可能需要设置responseType可以使用`withResponseType`函数进行设置,默认是`code` 还可以设置为`id_token``code` & `id_token`
> <https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/>
```php
$config = [
'paypal' => [
'client_id' => 'AT******************',
'client_secret' => 'EK**************',
'sandbox' => false,
'redirect_url'=>"nativexo://paypalpay",
],
];
```
## 其他一些技巧
### Scopes
@ -498,7 +511,7 @@ $socialite->withRedirectUrl($url)->redirect();
```php
<?php
session_start();
$config = [
//...
];
@ -510,7 +523,7 @@ $socialite = new SocialiteManager($config);
$url = $socialite->create('github')->withState($state)->redirect();
return redirect($url);
return redirect($url);
```
### 检验回调的 `state`
@ -520,10 +533,10 @@ return redirect($url);
```php
<?php
session_start();
$state = request()->query('state');
$code = request()->query('code');
// Check the state received with current session id
if ($state != hash('sha256', session_id())) {
exit('State does not match!');
@ -544,10 +557,9 @@ $response = $socialite->create('google')
->with(['hd' => 'example.com'])->redirect();
```
## User interface
### 标准的 user api
### 标准的 user api
```php
$user = $socialite->create('github')->userFromCode($code);
@ -596,7 +608,7 @@ mixed $user->getId();
?string $user->getEmail();
?string $user->getAvatar();
?string $user->getRaw();
?string $user->getAccessToken();
?string $user->getAccessToken();
?string $user->getRefreshToken();
?int $user->getExpiresIn();
?array $user->getTokenResponse();
@ -604,7 +616,7 @@ mixed $user->getId();
```
### 从 OAuth API 响应中取得原始数据
### 从 OAuth API 响应中取得原始数据
`$user->getRaw()` 方法会返回一个 **array**
@ -612,7 +624,7 @@ mixed $user->getId();
`$user->getTokenResponse()` 方法会返回一个 **array** 里面是响应从获取 token 时候 API 返回的响应。
> 注意:当你使用 `userFromCode()` 时,这个方法只返回一个 **有效的数组**,否则将返回 **null**,因为 `userFromToken() ` 没有 token 的 HTTP 响应。
> 注意:当你使用 `userFromCode()` 时,这个方法只返回一个 **有效的数组**,否则将返回 **null**,因为 `userFromToken()` 没有 token 的 HTTP 响应。
### 通过 access token 获取用户信息
@ -621,11 +633,9 @@ $accessToken = 'xxxxxxxxxxx';
$user = $socialite->userFromToken($accessToken);
```
## Enjoy it! :heart:
# Enjoy it! :heart:
# 参照
## 参照
- [Alipay - 用户信息授权](https://opendocs.alipay.com/open/289/105656)
- [DingTalk - 扫码登录第三方网站](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3)
@ -648,15 +658,14 @@ $user = $socialite->userFromToken($accessToken);
- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093)
- [Line - OAuth 2.0](https://developers.line.biz/en/docs/line-login/integrate-line-login/)
- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)
- [PayPal - OAuth文档](https://developer.paypal.com/docs/log-in-with-paypal/)
# PHP 扩展包开发
## PHP 扩展包开发
> 想知道如何从零开始构建 PHP 扩展包?
>
> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)
# License
## License
MIT

21
vendor/overtrue/socialite/README_EN.md vendored Executable file → Normal file
View File

@ -443,6 +443,26 @@ $config = [
];
```
### [PayPal](https://developer.paypal.com/docs/log-in-with-paypal/)
You may need to set the responseType, which can be set using the `withResponseType` function. The default is `code` and can also be set to `id_token` or `code` & `id_token`
> https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/
```php
$config = [
'paypal' => [
'client_id' => 'AT******************',
'client_secret' => 'EK**************',
'sandbox' => false,
'redirect_url'=>"nativexo://paypalpay",
],
];
```
## Some Skill
### Scopes
@ -627,6 +647,7 @@ $user = $socialite->userFromToken($accessToken);
- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093)
- [Line - OAuth 2.0](https://developers.line.biz/en/docs/line-login/integrate-line-login/)
- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)
- [PayPal - OAuth文档](https://developer.paypal.com/docs/log-in-with-paypal/)
[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)

6
vendor/overtrue/socialite/composer.json vendored Executable file → Normal file
View File

@ -25,13 +25,11 @@
"php": ">=8.0.2",
"ext-json": "*",
"ext-openssl": "*",
"guzzlehttp/guzzle": "^7.0",
"symfony/http-foundation": "^6.0",
"symfony/psr-http-message-bridge": "^2.1"
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^11.3",
"jetbrains/phpstorm-attributes": "^1.0",
"phpstan/phpstan": "^1.7",
"laravel/pint": "^1.2"

0
vendor/overtrue/socialite/phpstan.neon.dist vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/phpunit.xml vendored Executable file → Normal file
View File

3
vendor/overtrue/socialite/src/Config.php vendored Executable file → Normal file
View File

@ -9,9 +9,6 @@ class Config implements ArrayAccess, JsonSerializable
{
protected array $config;
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;

0
vendor/overtrue/socialite/src/Contracts/FactoryInterface.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Contracts/ProviderInterface.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Contracts/UserInterface.php vendored Executable file → Normal file
View File

View File

4
vendor/overtrue/socialite/src/Exceptions/BadRequestException.php vendored Executable file → Normal file
View File

@ -2,6 +2,4 @@
namespace Overtrue\Socialite\Exceptions;
class BadRequestException extends Exception
{
}
class BadRequestException extends Exception {}

0
vendor/overtrue/socialite/src/Exceptions/Exception.php vendored Executable file → Normal file
View File

View File

@ -4,6 +4,4 @@ namespace Overtrue\Socialite\Exceptions\FeiShu;
use Overtrue\Socialite\Exceptions;
class InvalidTicketException extends Exceptions\Exception
{
}
class InvalidTicketException extends Exceptions\Exception {}

View File

0
vendor/overtrue/socialite/src/Exceptions/InvalidTokenException.php vendored Executable file → Normal file
View File

View File

0
vendor/overtrue/socialite/src/Providers/Alipay.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Azure.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Baidu.php vendored Executable file → Normal file
View File

26
vendor/overtrue/socialite/src/Providers/Base.php vendored Executable file → Normal file
View File

@ -15,29 +15,29 @@ abstract class Base implements Contracts\ProviderInterface
{
public const NAME = null;
protected ?string $state = null;
protected ?string $state = null;
protected Config $config;
protected Config $config;
protected ?string $redirectUrl;
protected ?string $redirectUrl;
protected array $parameters = [];
protected array $parameters = [];
protected array $scopes = [];
protected array $scopes = [];
protected string $scopeSeparator = ',';
protected string $scopeSeparator = ',';
protected GuzzleClient $httpClient;
protected array $guzzleOptions = [];
protected array $guzzleOptions = [];
protected int $encodingType = PHP_QUERY_RFC1738;
protected int $encodingType = PHP_QUERY_RFC1738;
protected string $expiresInKey = Contracts\RFC6749_ABNF_EXPIRES_IN;
protected string $expiresInKey = Contracts\RFC6749_ABNF_EXPIRES_IN;
protected string $accessTokenKey = Contracts\RFC6749_ABNF_ACCESS_TOKEN;
protected string $accessTokenKey = Contracts\RFC6749_ABNF_ACCESS_TOKEN;
protected string $refreshTokenKey = Contracts\RFC6749_ABNF_REFRESH_TOKEN;
protected string $refreshTokenKey = Contracts\RFC6749_ABNF_REFRESH_TOKEN;
public function __construct(array $config)
{
@ -53,7 +53,7 @@ abstract class Base implements Contracts\ProviderInterface
// normalize Contracts\RFC6749_ABNF_CLIENT_ID
if (! $this->config->has(Contracts\RFC6749_ABNF_CLIENT_ID)) {
$id = $this->config->get(Contracts\ABNF_APP_ID);
if (null != $id) {
if ($id != null) {
$this->config->set(Contracts\RFC6749_ABNF_CLIENT_ID, $id);
}
}
@ -61,7 +61,7 @@ abstract class Base implements Contracts\ProviderInterface
// normalize Contracts\RFC6749_ABNF_CLIENT_SECRET
if (! $this->config->has(Contracts\RFC6749_ABNF_CLIENT_SECRET)) {
$secret = $this->config->get(Contracts\ABNF_APP_SECRET);
if (null != $secret) {
if ($secret != null) {
$this->config->set(Contracts\RFC6749_ABNF_CLIENT_SECRET, $secret);
}
}

2
vendor/overtrue/socialite/src/Providers/Coding.php vendored Executable file → Normal file
View File

@ -11,7 +11,7 @@ use Overtrue\Socialite\User;
class Coding extends Base
{
public const NAME = 'coding';
public const NAME = 'coding';
// example: https://{your-team}.coding.net
protected string $teamUrl;

0
vendor/overtrue/socialite/src/Providers/DingTalk.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/DouYin.php vendored Executable file → Normal file
View File

1
vendor/overtrue/socialite/src/Providers/Douban.php vendored Executable file → Normal file
View File

@ -25,7 +25,6 @@ class Douban extends Base
}
/**
* @param string $token
* @param ?array $query
*/
protected function getUserByToken(string $token, ?array $query = []): array

4
vendor/overtrue/socialite/src/Providers/Facebook.php vendored Executable file → Normal file
View File

@ -17,9 +17,9 @@ class Facebook extends Base
protected string $version = 'v3.3';
protected array $fields = ['first_name', 'last_name', 'email', 'gender', 'verified'];
protected array $fields = ['first_name', 'last_name', 'email', 'gender', 'verified', 'picture'];
protected array $scopes = ['email'];
protected array $scopes = [];
protected bool $popup = false;

2
vendor/overtrue/socialite/src/Providers/FeiShu.php vendored Executable file → Normal file
View File

@ -21,7 +21,7 @@ class FeiShu extends Base
protected string $expiresInKey = 'refresh_expires_in';
protected bool $isInternalApp = false;
protected bool $isInternalApp = false;
public function __construct(array $config)
{

0
vendor/overtrue/socialite/src/Providers/Figma.php vendored Executable file → Normal file
View File

4
vendor/overtrue/socialite/src/Providers/GitHub.php vendored Executable file → Normal file
View File

@ -9,9 +9,9 @@ use Overtrue\Socialite\User;
class GitHub extends Base
{
public const NAME = 'github';
public const NAME = 'github';
protected array $scopes = ['read:user'];
protected array $scopes = ['read:user'];
protected string $scopeSeparator = ' ';

0
vendor/overtrue/socialite/src/Providers/Gitee.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Google.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Lark.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Line.php vendored Executable file → Normal file
View File

8
vendor/overtrue/socialite/src/Providers/Linkedin.php vendored Executable file → Normal file
View File

@ -51,7 +51,7 @@ class Linkedin extends Base
$response = $this->getHttpClient()->get($url, [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Authorization' => 'Bearer '.$token,
'X-RestLi-Protocol-Version' => '2.0.0',
],
]);
@ -65,7 +65,7 @@ class Linkedin extends Base
$response = $this->getHttpClient()->get($url, [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Authorization' => 'Bearer '.$token,
'X-RestLi-Protocol-Version' => '2.0.0',
],
]);
@ -75,11 +75,11 @@ class Linkedin extends Base
protected function mapUserToObject(array $user): Contracts\UserInterface
{
$preferredLocale = ($user['firstName']['preferredLocale']['language'] ?? 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;
$name = $firstName.' '.$lastName;
$images = $user['profilePicture']['displayImage~']['elements'] ?? [];
$avatars = \array_filter($images, static fn ($image) => ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 100);

0
vendor/overtrue/socialite/src/Providers/OpenWeWork.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Outlook.php vendored Executable file → Normal file
View File

View File

@ -0,0 +1,150 @@
<?php
namespace Overtrue\Socialite\Providers;
use JetBrains\PhpStorm\Pure;
use Overtrue\Socialite\Contracts;
use Overtrue\Socialite\User;
/**
* Class PayPal
*
* @author zhiqiang
*
* @see https://developer.paypal.com/docs/log-in-with-paypal/
*/
class PayPal extends Base
{
public const NAME = 'paypal';
protected string $scopeSeparator = ' ';
/**
* @var string|null
* code or id_token
*/
protected ?string $responseType = Contracts\RFC6749_ABNF_CODE;
protected string $flowEntry = 'static';
protected string $authUrl = 'https://www.paypal.com/signin/authorize';
protected string $tokenURL = 'https://api-m.paypal.com/v1/oauth2/token';
protected string $userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo?schema=openid';
protected array $scopes = [
'openid', 'profile', 'email', 'address',
];
protected bool $sandbox = true;
public function __construct(array $config)
{
parent::__construct($config);
$this->sandbox = (bool)$this->config->get('sandbox', false);
if ($this->sandbox) {
$this->authUrl = 'https://www.sandbox.paypal.com/signin/authorize';
$this->tokenURL = 'https://api-m.sandbox.paypal.com/v1/oauth2/token';
$this->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo?schema=openid';
}
}
/**
* @return $this
*
* @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/
*/
public function withResponseType(?string $responseType)
{
$this->responseType = $responseType;
return $this;
}
protected function getAuthUrl(): string
{
return $this->buildAuthUrlFromBase($this->authUrl);
}
protected function getCodeFields(): array
{
$fields = \array_merge(
[
'flowEntry' => $this->flowEntry,
Contracts\RFC6749_ABNF_CLIENT_ID => $this->getClientId(),
Contracts\RFC6749_ABNF_RESPONSE_TYPE => $this->responseType,
Contracts\RFC6749_ABNF_SCOPE => $this->formatScopes($this->scopes, $this->scopeSeparator),
Contracts\RFC6749_ABNF_REDIRECT_URI => $this->redirectUrl,
],
$this->parameters
);
if ($this->state) {
$fields[Contracts\RFC6749_ABNF_STATE] = $this->state;
}
return $fields;
}
protected function getTokenUrl(): string
{
return $this->tokenURL;
}
/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
*
* @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-getaccesstoken
*
*/
public function tokenFromCode(string $code): array
{
$response = $this->getHttpClient()->post(
$this->getTokenUrl(),
[
'form_params' => [
Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_CLIENT_CREDENTIALS,
Contracts\RFC6749_ABNF_CODE => $code,
],
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic ' . \base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())),
],
]
);
return $this->normalizeAccessTokenResponse((string)$response->getBody());
}
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @see https://developer.paypal.com/docs/api/identity/v1/#userinfo_get
*/
protected function getUserByToken(string $token): array
{
$response = $this->getHttpClient()->get(
$this->userinfoURL,
[
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Bearer ' . $token,
],
]
);
return $this->fromJsonBody($response);
}
#[Pure]
protected function mapUserToObject(array $user): Contracts\UserInterface
{
$user[Contracts\ABNF_ID] = $user['user_id'] ?? null;
$user[Contracts\ABNF_NICKNAME] = $user['given_name'] ?? $user['family_name'] ?? $user['middle_name'] ?? null;
$user[Contracts\ABNF_NAME] = $user['name'] ?? '';
$user[Contracts\ABNF_EMAIL] = $user[Contracts\ABNF_EMAIL] ?? null;
$user[Contracts\ABNF_AVATAR] = $user['picture'] ?? null;
return new User($user);
}
}

0
vendor/overtrue/socialite/src/Providers/QCloud.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/QQ.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Taobao.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Tapd.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/TouTiao.php vendored Executable file → Normal file
View File

19
vendor/overtrue/socialite/src/Providers/WeChat.php vendored Executable file → Normal file
View File

@ -114,7 +114,7 @@ class WeChat extends Base
public function userFromCode(string $code): Contracts\UserInterface
{
if (\in_array('snsapi_base', $this->scopes)) {
return $this->mapUserToObject($this->fromJsonBody($this->getTokenFromCode($code)));
return $this->getSnsapiBaseUserFromCode($code);
}
$token = $this->tokenFromCode($code);
@ -128,6 +128,19 @@ class WeChat extends Base
->setTokenResponse($token);
}
protected function getSnsapiBaseUserFromCode(string $code): Contracts\UserInterface
{
$token = $this->fromJsonBody($this->getTokenFromCode($code));
$user = [
'openid' => $token['openid'],
];
if (isset($token['unionid'])) {
$user['unionid'] = $token['unionid'];
}
return $this->mapUserToObject($token)->setProvider($this)->setRaw($user)->setAccessToken($token[$this->accessTokenKey]);
}
protected function getUserByToken(string $token): array
{
$language = $this->withCountryCode ? null : (isset($this->parameters['lang']) ? $this->parameters['lang'] : 'zh_CN');
@ -205,11 +218,11 @@ class WeChat extends Base
}
}
if (2 !== \count($config)) {
if (\count($config) !== 2) {
throw new Exceptions\InvalidArgumentException('Please check your config arguments were available.');
}
if (1 === \count($this->scopes) && \in_array('snsapi_login', $this->scopes)) {
if (\count($this->scopes) === 1 && \in_array('snsapi_login', $this->scopes)) {
$this->scopes = ['snsapi_base'];
}

0
vendor/overtrue/socialite/src/Providers/WeWork.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/Weibo.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/src/Providers/XiGua.php vendored Executable file → Normal file
View File

1
vendor/overtrue/socialite/src/SocialiteManager.php vendored Executable file → Normal file
View File

@ -40,6 +40,7 @@ class SocialiteManager implements Contracts\FactoryInterface
Providers\WeWork::NAME => Providers\WeWork::class,
Providers\Weibo::NAME => Providers\Weibo::class,
Providers\XiGua::NAME => Providers\XiGua::class,
Providers\PayPal::NAME => Providers\PayPal::class,
];
#[Pure]

2
vendor/overtrue/socialite/src/Traits/HasAttributes.php vendored Executable file → Normal file
View File

@ -68,7 +68,7 @@ trait HasAttributes
{
$result = \json_encode($this->getAttributes(), JSON_UNESCAPED_UNICODE);
false === $result && throw new Exceptions\Exception('Cannot Processing this instance as JSON stringify.');
$result === false && throw new Exceptions\Exception('Cannot Processing this instance as JSON stringify.');
return $result;
}

0
vendor/overtrue/socialite/src/User.php vendored Executable file → Normal file
View File

2
vendor/overtrue/socialite/tests/OAuthTest.php vendored Executable file → Normal file
View File

@ -199,8 +199,6 @@ class OAuthTestProviderStub extends Base
/**
* Get a fresh instance of the Guzzle HTTP client.
*
* @return \GuzzleHttp\Client
*/
public function getHttpClient(): GuzzleHttp\Client
{

0
vendor/overtrue/socialite/tests/Providers/FeiShuTest.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/tests/Providers/WeWorkTest.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/tests/Providers/WechatTest.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/tests/SocialiteManagerTest.php vendored Executable file → Normal file
View File

0
vendor/overtrue/socialite/tests/UserTest.php vendored Executable file → Normal file
View File