运气不错,没有报错,所以用简易方式列表展示我的安装步骤,用来记录。可以略过不看,看下一篇技巧:jwt让管理员和用户使用不同的guard/数据表验证。

1、安装git,设置环境变量。https://www.cnblogs.com/qingmuchuanqi48/p/12052289.html,如果不安装,composer update时候有可能会出现警告错误。

2、安装dingo,我没有用composer 命令安装,参考官方文档,一定要看第一个表格中版本的说明:https://github.com/dingo/api/wiki/Installation

3、打开 composer.json ,添加:【在require下添加“dingo/api“: “^3.0.0“】即可。

"require": {

"dingo/api": "^3.0.0"

}

1

2

3

"require":{

"dingo/api":"^3.0.0"

}

4、运行 composer update 安装。

5、发布一下配置:

php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

1

phpartisanvendor:publish--provider="Dingo\Api\Provider\LaravelServiceProvider"

在根目录下的.env下

API_STANDARDS_TREE=x //分支说明

API_SUBTYPE="${APP_NAME}" //通常是说app的短名称  一般小写

API_PREFIX=api //前缀和子域 可以使用域名,比如api.123.com 不要加/

API_VERSION=v1 //

API_NAME="51SEO API"

API_STRICT=false //严格模式

API_DEFAULT_FORMAT=json //响应模式

API_DEBUG=false

1

2

3

4

5

6

7

8

API_STANDARDS_TREE=x//分支说明

API_SUBTYPE="${APP_NAME}"//通常是说app的短名称  一般小写

API_PREFIX=api//前缀和子域 可以使用域名,比如api.123.com 不要加/

API_VERSION=v1//

API_NAME="51SEO API"

API_STRICT=false//严格模式

API_DEFAULT_FORMAT=json//响应模式

API_DEBUG=false

7、先不考虑路由配置,先安装jwt:composer require tymon/jwt-auth,官方文档:https://jwt-auth.readthedocs.io/en/develop/

8、发布资源:php artisan vendor:publish –provider=“Tymon\JWTAuth\Providers\LaravelServiceProvider”

9、生成jwt的key: php artisan jwt:secret

10、进行配置

在根目录下的.env下

JWT_SECRET=key值 //php artisan jwt:secret 自动生成的

JWT_TTL=60 #token有效期,默认60分钟,单位分钟,ttl失效,refresh_ttl有效时可以刷新获取新的token

JWT_REFRESH_TTL=20160 #token允许刷新时间,默认20160分钟(2周),单位分钟,refresh_ttl失效后,需要重新登陆。

JWT_BLACKLIST_ENABLED=true #黑名单,默认true,建议开启,不开启无法让token失效。

JWT_BLACKLIST_GRACE_PERIOD=10 #宽限时间,单位秒,ttl失效,refresh_ttl有效时宽限时间内的请求会被允许;并发请求时,token被刷新后,防止后续请求失败。

1

2

3

4

5

JWT_SECRET=key值//php artisan jwt:secret 自动生成的

JWT_TTL=60#token有效期,默认60分钟,单位分钟,ttl失效,refresh_ttl有效时可以刷新获取新的token

JWT_REFRESH_TTL=20160#token允许刷新时间,默认20160分钟(2周),单位分钟,refresh_ttl失效后,需要重新登陆。

JWT_BLACKLIST_ENABLED=true#黑名单,默认true,建议开启,不开启无法让token失效。

JWT_BLACKLIST_GRACE_PERIOD=10#宽限时间,单位秒,ttl失效,refresh_ttl有效时宽限时间内的请求会被允许;并发请求时,token被刷新后,防止后续请求失败。

11、./config/app.php 配置 ‘providers’项添加:

Tymon\JWTAuth\Providers\LaravelServiceProvider::class, //add jwt服务

Dingo\Api\Provider\LaravelServiceProvider::class, //add api接口服务

1

2

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,//add jwt服务

Dingo\Api\Provider\LaravelServiceProvider::class,//add api接口服务

12、./config/app.php 配置 ‘aliases’项添加:

'API' => Dingo\Api\Facade\API::class, //dingo api //提供好用的辅助方法

'ApiRoute' => Dingo\Api\Facade\Route::class, //dingo apiRoute //可以获取当前api路由 检查当前路由的名称等等

'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class, //jwt

'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class, //jwt

1

2

3

4

'API'=>Dingo\Api\Facade\API::class,//dingo api //提供好用的辅助方法

'ApiRoute'=>Dingo\Api\Facade\Route::class,//dingo apiRoute  //可以获取当前api路由 检查当前路由的名称等等

'JWTAuth'=>Tymon\JWTAuth\Facades\JWTAuth::class,//jwt

'JWTFactory'=>Tymon\JWTAuth\Facades\JWTFactory::class,//jwt

13、./config/api.php 修改 ‘auth’项(第170行左右),用于设置dingo的api验证方式:

'jwt' => 'Dingo\Api\Auth\Provider\JWT',

1

'jwt'=>'Dingo\Api\Auth\Provider\JWT',

14、数据库表【用于用户验证的表】配置

<?php

namespace App\Models;

use Encore\Admin\Traits\DefaultDatetimeFormat;

use Tymon\JWTAuth\Contracts\JWTSubject; //*这里是新增

use Illuminate\Notifications\Notifiable; //*这里是新增

use Illuminate\Foundation\Auth\User as Authenticatable; //*这里是修改

class AdminUser extends Authenticatable implements JWTSubject //*这里是修改

{

//JWT

use Notifiable; //*这里是新增

//格式化日期显示

use DefaultDatetimeFormat;

//指定表名 因为表名带s

protected $table = 'admin_users';

protected $fillable = [];

protected $guarded = [

'remember_token'

];

/**

* The attributes that should be hidden for arrays.

*

* @var array

*/

protected $hidden = [

'password',

'remember_token',

];

//实现 JWTSubject接口 新增 两个函数

/**

* Get the identifier that will be stored in the subject claim of the JWT.

*

* @return mixed

*/

public function getJWTIdentifier()

{

return $this->getKey();

}

/**

* Return a key value array, containing any custom claims to be added to the JWT.

*

* @return array

*/

public function getJWTCustomClaims()

{

return [];

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

<?php

namespaceApp\Models;

useEncore\Admin\Traits\DefaultDatetimeFormat;

useTymon\JWTAuth\Contracts\JWTSubject;//*这里是新增

useIlluminate\Notifications\Notifiable;//*这里是新增

useIlluminate\Foundation\Auth\UserasAuthenticatable;//*这里是修改

classAdminUserextendsAuthenticatableimplementsJWTSubject//*这里是修改

{

//JWT

useNotifiable;//*这里是新增

//格式化日期显示

useDefaultDatetimeFormat;

//指定表名 因为表名带s

protected$table='admin_users';

protected$fillable=[];

protected$guarded=[

'remember_token'

];

/**

* The attributes that should be hidden for arrays.

*

* @var array

*/

protected$hidden=[

'password',

'remember_token',

];

//实现 JWTSubject接口 新增 两个函数

/**

* Get the identifier that will be stored in the subject claim of the JWT.

*

* @return mixed

*/

publicfunctiongetJWTIdentifier()

{

return$this->getKey();

}

/**

* Return a key value array, containing any custom claims to be added to the JWT.

*

* @return array

*/

publicfunctiongetJWTCustomClaims()

{

return[];

}

}

dingo php,laravel 使用dingo 和 jwt 【laravel7.3 dingo3.0 php7.3】配置相关推荐

  1. php dingo和jwt,dingo配合laravel、JWT使用

    介绍:dingo api包是给laravel和lumen提供的Restful的工具包,它可以与jwt组件一起配合快速的完成用户认证,同时对于数据和运行过程中所产生的异常能够捕获到并且可以做出对应的响应 ...

  2. Laravel使用Dingo API+JWT实现认证机制 无痛刷新Token

    Laravel使用Dingo API+JWT实现认证机制 无痛刷新Token 一.安装[Dingo API](https://github.com/dingo/api) 和 [JWT](https:/ ...

  3. php dingo和jwt,Laravel实现dingo+JWT api接口之配置篇

    尝试了下在简书写博客..结果一般如下: 废话不多说,直接进入----| 1. 安装拓展包 一.集成dingo ①在composer.json的require字段中添加:"dingo/api& ...

  4. Laravel实现dingo+JWT api接口之实战篇

    文章来源:https://blog.csdn.net/qq_28666081/article/details/52188549 展开 上一篇文章讲解了如何配置安装包(点击这里),接下来讲解如何使用 这 ...

  5. dingo php,Laravel+Dingo/Api 自定义响应的实现

    在最近的开发开发项目中,我使用了Dingo/Api这个第三方Api库. Dingo是个很强大的Api库, 但在开发的过程中,需要自定义响应字段. 刚开始使用Ding/Api时,返回如下: { &quo ...

  6. laravel 5.5 整合 jwt 报错Method Tymon\JWTAuth\Commands\JWTGenerateCommand::handle() does not exist解决...

    今天介绍一个在laravel5.5新版本整合jwt  执行 php artisan jwt:generate 再生成密钥时报的一个错误 Method Tymon\JWTAuth\Commands\JW ...

  7. laravel mysql 锁表_Laravel 数据库加密及数据库表前缀配置方法

    报错问题:DecryptException in Encrypter.php line 148: The MAC is invalid. 如何运行 php artisan key:generate 这 ...

  8. Laravel框架学习笔记(一)——phpstudy下的安装配置

    2019独角兽企业重金招聘Python工程师标准>>> 网上关于如何安装laravel框架的教程很多,就不多说了,推荐大家去看http://www.golaravel.com/里的教 ...

  9. Laravel中的env函数获取不到确定存在的配置

    我的个人博客:逐步前行STEP 今天重启服务器后发现网站有个报错,一看是获取配置出错,于是去检查配置,发现没问题,配置是正确的,于是想着换成getenv函数试试,还是不行,执行一遍composer i ...

  10. 微信中分享html5网页sdk,微信SDK网页分享

    步骤一:绑定域名 先登录微信公众平台进入"公众号设置"的"功能设置"里填写"JS接口安全域名". image.png 步骤二:引入JS文件 ...

最新文章

  1. 知识管理系统Data Solution研发日记之六 窗体设计器
  2. [html] 一个标签上同时出现三个或多个class属性,请问它的渲染顺序是怎样的?
  3. vs2017 cmake android,CMake构建VS2017工程
  4. C++ const成员变量和成员函数
  5. 动态规划解题一般思路
  6. 微博抽奖贴为什么到时间了不开奖_热搜第一!微博闹剧,锦鲤“信小呆”被这样处罚...
  7. 阻尼衰减曲线用python_阻尼的反击 | 被半篇论文爆脑两次是一种什么体验
  8. 浏览器 刷新页面后回到顶部_当你在浏览器中,忘记了曾经的登录密码怎么办......
  9. fopen文件路径怎么写_php的多功能文件操作类
  10. Linux Autofs自动挂载服务详解
  11. VisualVM初次使用BTrace功能方法步骤
  12. 台达伺服ASD-B2的调试
  13. 《自控力》——凯利.麦格尼格尔
  14. GGC/ITF/国自然
  15. 智能硬件成在线教育救命稻草?
  16. 区块链2.0以太坊漫谈(3)
  17. 函数中的arguments
  18. 大数据推荐算法概念简述
  19. 知识图谱——领域知识问答系统简单介绍
  20. 树莓派 Python编写OLED显示程序

热门文章

  1. 【web前端】第二天-HTML标签(下)
  2. React Native引用三方库报错underfined is not an object(evaluating 'viewproptypes.style')
  3. JetBrain学生认证续费步骤
  4. oracle入门操作3(关于查询 )
  5. OpenCV学习Rosenfeld细化算法
  6. Android 第三方 ROM
  7. HTC M7日版HTL22刷机包 毒蛇2.5.0 ART NFC Sense6.0
  8. /sdcard目录详解
  9. 2013年计算机毕业生流向,2013年计算机专业应届毕业生自我鉴定
  10. 4G手机网络免费开通高清语音VoLTE