laravel jwt.provider相關

#動態改動jwt配置

    $abstract = 'tymon.jwt.provider.jwt.lcobucci';
    $raw = app($abstract);

    app()->instance($abstract, new \Tymon\JWTAuth\Providers\JWT\Lcobucci(
        new JWTBuilder(),
        new JWTParser(),
        '112233',
        config("jwt.algo"),
        config("jwt.keys")
    ));
    $a1 = app($abstract);

    app()->instance($abstract, $raw);
    $a2 = app($abstract);
    dd($raw, $a1, $a2);


    app()->forgetInstance($abstract);
    app()->singleton('tymon.jwt.provider.jwt.lcobucci', function ($app) {
        return new \Tymon\JWTAuth\Providers\JWT\Lcobucci(
            new JWTBuilder(),
            new JWTParser(),
            '112233',
            config("jwt.algo"),
            config("jwt.keys")
        );
    });
#########################################
app('auth')->guard()->tokenById(1); #簡單生成sub爲1的token;會查詢一次數據庫

app('auth')->guard()->login(JwtSubject $userModel); #生成token,並設置JWT實例的token屬性;設置全局user,使得Auth::user()能夠拿到登陸的信息

app('auth')->guard()->attempt($credentials); #根據知足該憑證的JwtSubject, 如UserModel;知足則調用login
相關文章
相關標籤/搜索