2017 © Pedro Peláez
 

library yii2-kuainiu

kuainiu.io extenion for using via yii2-authclient

image

kuainiu/yii2-kuainiu

kuainiu.io extenion for using via yii2-authclient

  • Friday, March 30, 2018
  • by summic
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

yii2-kuainiu

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

This extension adds kuainiu.io OAuth2 supporting for yii2-authclient., (*2)

安装

yii2-kuainiu 需要使用 composer 安装. 建议使用 composer 国内源 composer config repo.packagist composer https://packagist.phpcomposer.com, (*3)

在项目根目录运行, (*4)

composer require kuainiu/yii2-kuainiu

或者手动添加到 composer.json, (*5)

"kuainiu/yii2-kuainiu": "*"

之后, (*6)

composer install -vvv

配置

首先需要在 内部通行证系统 注册您的应用, (*7)

然后修改需使用统一登录项目的配置文件(main.php 或 main-local.php), (*8)

//按需配置
'modules' => [
    'kuainiu' => [
        'class' => 'kuainiu\Module',
    ],
    ...
],

authClient 的配置需要放在 common 项目的配置文件(main.php 或 main-local.php ), (*9)

//全局配置
$config = [
    'components' => [
        'authClientCollection' => [
            'class' => 'yii\authclient\Collection',
            'clients' => [
                'kuainiu' => [
                    'class' => 'kuainiu\components\authclient\Kuainiu',
                    'clientId' => 'kuainiu_client_id',
                    'clientSecret' => 'kuainiu_client_secret',
                    'authUrl' => 'https://*domain*/auth',
                    'tokenUrl' => 'https://*domain*/auth/token',
                    'apiBaseUrl' => 'https://*domain*/api'
                ],
            ],
        ],
    ]
];
 ```


执行数据迁移:

```shell
yii migrate --migrationPath=@vendor/kuainiu/yii2-kuainiu/migrations

以上脚本在 user 表增加了 avatar fullname position 三个字段用来存储头像、中文名和职位,字段名冲突或有错误的话,可以在 modules 中配置,例如:, (*10)

'modules' => [
    'kuainiu' => [
        'class' => 'kuainiu\Module',
        'tableMap' => [ // Optional, but if defined, all must be declared
            'user_table'            =>  '{{%user}}',
            'username_field'        =>  'name',
            'email_field'           =>  'email',
            'password_hash_field'   =>  'password_hash',
            'fullname_field'        =>  'chinese_name',
            'avatar_field'          =>  'avatar',
            'position_field'        =>  'position',
        ],
        'profileMap' => [ // Optional, but if defined, all must be declared
            'username_field'        =>  'name',
            'email_field'           =>  'email',
            'fullname_field'        =>  'chinese_name',
            'avatar_field'          =>  'avatar',
            'position_field'        =>  'position',
        ],
    ],
    ...
],

使用

OAuth 登录

在登录页面增加 『使用企业通行证登录』 链接, (*11)

<div class="social-auth-links text-center">
    <p class="text-light-blue">- 或 -</p>
    <a href="/kuainiu/user/auth?authclient=kuainiu" class="btn btn-block btn-social btn-dropbox">
        <i class="fa fa-ticket"></i>使用企业通行证登录
    </a>
</div>

或, (*12)

如果全站只允许员工访问,不需要登录页面,直接修改 SiteController 的 actionLogin 方法:, (*13)

public function actionLogin()
{
    if (!Yii::$app->user->isGuest) {
        return $this->goHome();
    }
    $this->redirect(['kuainiu/user/auth','authclient'=>'kuainiu']);
}

用户完成登录之后,用户资料的使用无任何变化,在 view 文件中直接使用, 注意: 用户未登录界面调用会抛异常, (*14)

//头像
<?=Yii::$app->user->identity->avatar?>
//帐号
<?=Yii::$app->user->identity->username?>
//中文名
<?=Yii::$app->user->identity->fullname?>
//职位
<?=Yii::$app->user->identity->position?>

API 获取组织架构信息

use kuainiu\components\KuainiuClient;
...
$client = new KuainiuClient();
$response = $client->DepartmentList(82);

API 获取组织架构下的用户信息

use kuainiu\components\KuainiuClient;
...
$client = new FondClient();
$response = $client->DepartmentUser(82);

API 发送企业微信消息

use kuainiu\components\KuainiuClient;
...
$client = new FondClient();
$response = $client->Notification('Allen', 'Hello World');

One more thing...

如果你的项目使用了 AdminLTE, 其使用的 GOOGLE 字体不可描述原因会导致页面打开慢,在 composer.json 增加以下内容可解决:, (*15)

"scripts": {
    "post-install-cmd": [
        "kuainiu\\components\\AdminLTEInstaller::initProject"
    ],
    "post-update-cmd": [
        "kuainiu\\components\\AdminLTEInstaller::initProject"
    ]
}

The Versions

30/03 2018

dev-master

9999999-dev https://github.com/kuainiu/yii2-kuainiu.git

kuainiu.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient kuainiu

30/03 2018

1.2.8

1.2.8.0 https://github.com/kuainiu/yii2-kuainiu.git

kuainiu.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient kuainiu

23/11 2017

1.2.7

1.2.7.0 https://github.com/kuainiu/yii2-kuainiu.git

kuainiu.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient kuainiu

22/11 2017

1.2.6

1.2.6.0 https://github.com/kuainiu/yii2-kuainiu.git

kuainiu.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient kuainiu

21/07 2017

1.2.5

1.2.5.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

22/02 2017

1.2.4

1.2.4.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

29/12 2016

1.2.3

1.2.3.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

27/12 2016

1.2.2

1.2.2.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

25/12 2016

1.2.1

1.2.1.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

24/12 2016

1.2.0

1.2.0.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

23/12 2016

1.1.0

1.1.0.0 https://github.com/summic/yii2-fond.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

20/12 2016

1.0.1

1.0.1.0 https://github.com/summic/yii2-fond-authclient.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond

20/12 2016

1.0.0

1.0.0.0 https://github.com/summic/yii2-fond-authclient.git

Fond.io extenion for using via yii2-authclient

  Sources   Download

MIT

The Requires

 

by Allen Wang

oauth yii2 authclient fond