Skip to content

admininfon/think-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THINK JWT

thinkphp json web token package, By unofficial.

使用扩展包

  • composer request kangst/think-jwt
  • 加载命令文件到服务并执行命令创建jwt.php配置文件
PATH:
config/console.php

CODE:
return [
    // 指令定义
    'commands' => [
        'jwt:generate' => \Kangst\JWTAuth\Console\GenerateConfigFile::class,
    ],
];

RUN COMMAND:
php think jwt:generate
  • jwt使用
namespace app\api\controller\v1;


use app\api\controller\Base;
use Kangst\JWTAuth\JWTAuth;

class User extends Base
{
    /**
     * @var JWTAuth
     */
    protected $auth;

    public function __construct($app = null, JWTAuth $auth)
    {
        parent::__construct($app);
        $this->auth = $auth;
    }

    public function login()
    {
        $credentials = $this->request->only(['name', 'email']);
        $token = $this->auth->attempt($credentials);
        $user = $this->auth->setToken($token)->user();
        $resh_token = $this->auth->setToken($token)->refresh();

        $data = array(
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => $this->auth->factory()->getTTL() * 60,
            'user' => $user->user()->toArray(),
            'resh_token' => $resh_token,
        );
        $this->result($data, 0, 'success', 'JSON');
    }
}

还在完善中,请多多Fork

项目地址:github
URL:https://github.com/admininfon/think-jwt

About

thinkphp json web token package.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages