anli / yii2-auth0
Yii2 Auth0
1.11.0
2016-04-12 04:04 UTC
Requires
- adoy/oauth2: dev-master
- anli/yii2-helper: *
- anli/yii2-metronic: *
- auth0/auth0-php: ~1.0
- firebase/php-jwt: v2.2.0
- yiisoft/yii2: *
README
Yii2 Auth0
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist anli/yii2-auth0 "*"
或者
"anli/yii2-auth0": "*"
将以下内容添加到你的 composer.json
文件的 require 部分。
使用以下命令运行迁移:
php yii migrate/up --migrationPath=@vendor/anli/yii2-auth0/migrations
配置
使用以下内容更新 modules
部分:
'auth0' => array_merge([
'class' => 'anli\auth0\Module',
'adminEmails' => ['anli@simbiosis.com.sg'],
], require(__DIR__ . '/auth0-local.php')),
在 config/auth0-local.php
中创建一个新文件
<?php
if (YII_ENV_DEV) {
return [
'serviceId' => '',
'domain' => '',
'clientId' => '',
'clientSecret' => '',
'redirectUrl' => '',
'apiTokens' => [
'usersRead' => '',
'usersUpdate' => '',
]
];
}
return [
'serviceId' => '',
'domain' => '',
'clientId' => '',
'clientSecret' => '',
'redirectUrl' => '',
'apiTokens' => [
'usersRead' => '',
'usersUpdate' => '',
]
];
将以下内容添加到你的 .gitignore
文件中
/config/auth0-local.php
在 auth0 登录并更新设置页面中的 Allowed Callback Urls
在配置中更新 components
部分
'user' => [
'identityClass' => 'anli\auth0\models\User',
'loginUrl' => ['auth0/user/login'],
],
'tenant' => [
'class' => 'anli\auth0\components\Tenant',
],
使用方法
将登录按钮的 url
部分更新为 [/auth0/user/login]
。
将登出按钮的 url
部分更新为 [/auth0/user/logout]
。
要显示登录用户,使用
Html::encode(Yii::$app->user->identity->username);
要显示登录租户,使用
Html::encode(Yii::$app->tenant->identity->name);
要自动更新 tenant_id,将以下内容添加到你的模型中 behaviors
部分
use anli\auth0\behaviors\TenantBehavior;
...
'tenant' => [
'class' => TenantBehavior::className(),
],
常见问题解答
如果你遇到以下错误
\JWT not found
将 firebase/php-jwt
的版本更改为 v2.2.0
cd @vendor/firebase/php-jwt
git checkout v2.2.0
更新 @vendor/composer/autoload_classmap.php
'BeforeValidException' => $vendorDir . '/firebase/php-jwt/Exceptions/BeforeValidException.php',
'JWT' => $vendorDir . '/firebase/php-jwt/Authentication/JWT.php',
如果你遇到以下错误
Cannot handle token prior to 2015-08-05T10:42:34+0200
并将你的系统时间向前调整几分钟。
如果你遇到以下错误
cURL error 60: SSL certificate problem: self signed certificate in certificate chain
下载 CA 到;
C:\xampp\php\ca\cacert.pem
并更新 C:\xampp\php\php.ini
curl.cainfo=C:\xampp\php\ca\cacert.pem
重启你的 apache2 服务器。