wfcreations / yii2-satellizer-server
Yii2 Satellizer server
dev-master
2015-08-21 21:57 UTC
Requires
- firebase/php-jwt: dev-master
- guzzlehttp/guzzle: 4.2.1
- guzzlehttp/oauth-subscriber: 0.1.2
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-21 05:50:59 UTC
README
Satellizer 是一个简单易用的端到端基于令牌的身份验证模块,用于 AngularJS,内置了对 Google、Facebook、LinkedIn、Twitter、Yahoo、Windows Live 身份验证提供商的支持,以及 Email 和密码登录。您不仅限于上述登录选项,实际上,您可以在配置步骤中通过传递特定于提供者的信息来添加任何 OAuth 1.0 或 OAuth 2.0 提供商。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
composer require "wfcreations/yii2-satellizer-server:*"
或者将以下内容添加到您的 composer.json
文件的 require
部分中。
"wfcreations/yii2-satellizer-server": "*",
使用方法
要使用此扩展,只需将以下代码添加到您的应用程序配置中
'components' => [ 'satellizer' => [ 'class' => \wfcreations\satellizer\Satellizer::className(), 'identityClass' => \common\models\ar\Advertiser::className(), 'tokenLifetime' => 2 * 7 * 24 * 60 * 60, 'jwtKey' => 'jwtsecret', 'facebook' => [ 'clientSecret' => 'facebookscecret', ], ], // ... ]
在您的认证控制器中
use yii\rest\Controller; class AuthController extends Controller { public function actions() { return [ 'facebook' => [ 'class' => 'wfcreations\satellizer\actions\FacebookAction', ], ]; } protected function verbs() { return [ 'facebook' => ['post', 'options'], ]; } // ... }
在其他需要认证用户的控制器中,只需在行为中配置认证器
'authenticator' => [ 'class' => HttpBearerAuth::className(), ],
如果您想获取认证用户
Yii::$app->user->identity
支持的提供商
- Foursquare
- Github
- 通过电子邮件和密码
有关 Yii2 API 的更多信息,请参阅 指南 - 快速入门 和 yii2-app-api。