Download the PHP package wenstionly/cache-token without Composer
On this page you can find all versions of the php package wenstionly/cache-token. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download wenstionly/cache-token
More information about wenstionly/cache-token
Files in wenstionly/cache-token
Download wenstionly/cache-token
More information about wenstionly/cache-token
Files in wenstionly/cache-token
Vendor wenstionly
Package cache-token
Short Description A token guard driver for laravel framework using independent cache system instead of databases.
License MIT
Package cache-token
Short Description A token guard driver for laravel framework using independent cache system instead of databases.
License MIT
Please rate this library. Is it a good library?
Informations about the package cache-token
Cache-Token
一个与TokenGuard类似的用户身份认证驱动。
与TokenGuard类似的是,Cache-Token通过在请求中附带一个api_token字段来向服务端传递用户身份令牌,以此识别用户身份。
与TokenGuard不同的是,Cache-Token还支持:
- 通过HTTP Header来传递令牌,Header域名称可以通过配置文件来设置
- 一个用户允许生成多个令牌,这些令牌的作用相同,从而实现多点同时登录,这一点与SessionGuard类似
- 区分个人电脑、手机、平板设备,并为不同的设备提供不同的互斥模式,例如,可以将手机端令牌设置为单点登录,而将个人电脑端设置为允许多点登录
版本兼容性
PHP | Laravel |
---|---|
>=7.2 | >=6.0 |
用法
参数配置分为两部分:
文件中可以配置令牌的存储方式:
- CACHE_TOKEN_STORE - 配置Cache存储介质,默认使用config('cache.default')的设置
-
CACHE_TOKEN_MAP_PREFIX 和 CACHE_TOKEN_USER_PREFIX - 配置令牌与用户id之间的映射缓存key的前缀,一般无需修改
文件用来配置令牌传输和认证参数。与TokenGuard的用法类似,在使用Cache-Token时,首先需要在guards中设置或新增一项。如下示例:
其中,
- 应当设置为 "cache-token"
- 作用与TokenGuard一致
- 用来设置通过表单(或json body)传输令牌时的Field名称
- 用来设置通过HTTP Header传输令牌时的Header Field名称
- 和 用来配置认证规则
- 和 只能出现其中一种,且 优先级高于
- 和 都没有出现时,等同于配置了
- 上述示例中给出的配置值,即为默认参数
- 配置说明:
- 用来配置token过期时间,单位:秒
- 用来配置是否为单点登录,true表示单点登录,false表示允许多点登录
- 配置说明:
- 数组的键名代表了不同的设备类型
- 数组中可以出现desktop/mobile/tablet中的0~3项配置项,没有出现的设置项将采用默认值
最后,在需要使用Cache-Token认证路由上设置中间件 即可(具体guard名称以 的配置为准)
处理登录/登出逻辑
以下假定在 中设置的CacheToken的guard名称为上述示例中的
登录
在处理完常规的用户认证逻辑后,如果登录成功,则可以通过下面的方式创建一个令牌:
登出
强制掉线
设备类型判断
驱动提供下列方法,方便判断用户的设备类型:
All versions of cache-token with dependencies
PHP Build Version
Package Version
The package wenstionly/cache-token contains the following files
Loading the files please wait ....