oom/luya-module-apiauth

安装: 24

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 3

分支: 1

开放问题: 0

类型:luya-module

1.0.0 2018-04-23 14:36 UTC

This package is not auto-updated.

Last update: 2024-09-24 10:07:58 UTC


README

Build Status

LUYA Api用户的oauth模块。

安装

通过composer安装此模块

composer require oom/luya-module-apiauth:dev-master

为了将模块添加到项目中,请进入配置的模块部分

return [
    'modules' => [
        // ...
        'api' => [
            'class' => 'oom\api\frontend\Module',
            'useAppViewPath' => true, // When enabled the views will be looked up in the @app/views folder, otherwise the views shipped with the module will be used.
        ],
        'apiadmin' => 'oom\api\admin\Module',
        // ...
    ],
];

使用内置的ApiAuthUser类启用用户组件,并添加REST URL规则

    'components' => [

        //...
        'user' => [
            'identityClass' => 'oom\api\models\APIAuthUser',
            'enableAutoLogin' => true,
            'enableSession' => false,
            'loginUrl' => null,
        ],
        'urlManager' => [
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => 'api/user'],
            ],
        ],
        // ...   
    ]   

示例用法

  1. 插入测试用户: http://your.domain/api/sign/signup-test
  2. http://your.domain/api/sign/token 发送POST请求,包含app_keyapp_secret数据,以获取访问令牌。

Step 2

  1. 使用创建的访问令牌测试API:http://your.domain/api/user/rules?token=ACCESS_TOKEN_FROM_TOKEN_REQUEST

Step 3