Laravel 5.4 Tymon JWT Auth Guard 驱动程序未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42680573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:30:50  来源:igfitidea点击:

Laravel 5.4 Tymon JWT Auth Guard Driver Not Defined

phplaraveljwt

提问by Imran Ali

I've implemented Tymon JWT for Laravel 5.4 & its working fine with users (default) model.

我已经为 Laravel 5.4 实现了 Tymon JWT,它与用户(默认)模型一起工作得很好。

However, I want it to work for api guard not default web.

但是,我希望它适用于 api 防护而不是默认网络。

If I set default guard to api & set api driver to token as:

如果我将默认保护设置为 api 并将 api 驱动程序设置为令牌:

'api' => [
        'driver' => 'token',
        'provider' => 'app_users',
    ],

I get following error

我收到以下错误

Call to undefined method Illuminate\Auth\TokenGuard::attempt()

If I set api driver to jwt-auth, I get follwing error

如果我将 api 驱动程序设置为 jwt-auth,则会出现以下错误

Auth guard driver [api] is not defined.

Interestingly it works fine If I change driver to session.

有趣的是,如果我将驱动程序更改为会话,它可以正常工作。

'api' => [
        'driver' => 'session',
        'provider' => 'api_users',
    ],

Just wanted to know what driver should I set for JWT api tokens, as session driver is for web only?

只是想知道我应该为 JWT api 令牌设置什么驱动程序,因为会话驱动程序仅适用于 Web?

回答by Imran Ali

Posting answer to my question:

发布我的问题的答案:

There is no guard support for JWT 0.5.You will need to use one of the latest 1.0.0-versions.

JWT 0.5没有防护支持您将需要使用最新的1.0.0-版本之一。

Thanks.

谢谢。

回答by Utwo

If you use Tymon JWT package, 1.0 beta version, you can implement jwt guard very easily.

如果你使用 Tymon JWT 包,1.0 测试版,你可以很容易地实现 jwt 保护。

Documentation for that feature is not ready yet, but you can follow this mini-tutorial https://github.com/tymondesigns/jwt-auth/issues/860

该功能的文档尚未准备好,但您可以按照此迷你教程https://github.com/tymondesigns/jwt-auth/issues/860