celebron / yii2-oauth2-social
2.0.2
2023-08-19 10:26 UTC
Requires
- php: ^8.2
- celebron/yii2-celebron-common: ^1.2
- yiisoft/http: ^1.2
- yiisoft/yii2: ^2.0
- yiisoft/yii2-bootstrap5: ^2.0
- yiisoft/yii2-httpclient: ^2.0
Requires (Dev)
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-09-29 20:41:27 UTC
README
Celebron Social Extension for Yii 2
此扩展为Yii 2.0框架提供HTTP客户端。
安装
composer require celebron/yii2-oauth2-social
配置
文件 frontend/config/main.php
,示例
...,
'bootstrap' => [..., 'social' ],
'components'=>[
'user' => [
'identityClass' => \common\models\User::class,
...
],
'social' => [
'class' => Celebron\socialSource\Configuration::class,
'socials' => [
[
'class' => Yandex::class, //Google::class и т.д.
'active' => true,
'clientId' => '...',
'clientSecret' => '...,
],
...
],
],
],
...
必须
- 在
bootstrap
中连接组件Configuration::class
,如示例所示; - 在组件
social
中设置变量$socials
,列出所有社交网络,按照Yii::createObject()
规则; - 实现接口
SocialUserInterface
和IdentityInterface
并连接到组件user
;- (如有必要)连接到
UserManagementTrait
。
- (如有必要)连接到
Configuration::class
[optional] string $route ('social') - роут для OAuth redirect path
[optional] string|null $paramsGroup (null) - ключ массива с настройками в \Yii::$app->params (null - не использовать)
[optional] array $socialEvents - массив событий ['название-события' => \Closure]
[required] Social[] $socials - список всех соц. сетей (Правило формирования \Yii::createObject())
[optional] \Closure|null $paramsHandler - настройка $params в Social классах
- 在
$socials
数组中,键可以省略,那么在注册时,键将是类的名称。 - 如果类实现了接口
CustomRequestInterface
,则键是必需的(会抛出异常) - 如果设置了
$paramsGroup
,则可以从 \Yii::$app->params[$paramsGroup][{socialName}] 中获取clientId
和clientSecret
配置 - 如果设置了
$paramsHandler
,则可以从 callback-function 获取clientId
和clientSecret
配置function($socialName):array { /** @var Configure $this */ }
认证类
OAuth2::class (Google::class, Yandex::class, ...)
namespace Celebron\socials
[optional] bool $activate (false) - активировать механизм
[optional] string $name - название для Widget
[optional] string $icon - иконка для Widget
[optional] bool $visible - отображение для Widget
[required|optional] $clientId (null) - OAuth clientId
[required|optional] $clientSecret (null) - OAuth clientSecret
如果未定义 $clientId
和 $clientSecret
,则将使用参数 $params['clientId']
和 $params['clientSecret']
,否则将抛出异常。取决于配置 Configure::$paramsGroup
和 Configure::$paramsHandler
社交网络控制台中的重定向链接(oauth2等)
https://сайт.ru/{route}/{social}
图例
{social} - название социальной сети (google, yandex и т.п.). Индекс массива Сonfigutation::$socials.
{route} - Настройка в классе Configuration