代码拉取完成,页面将自动刷新
gf 的 jwt 插件。
这个插件是 fork 了 https://github.com/appleboy/gin-jwt 插件,修改为 https://github.com/gogf/gf 插件.
下载安装
$ go get github.com/gogf/gf-jwt
导入
import "github.com/gogf/gf-jwt"
查看示例 example/auth/auth.go , 使用 ExtractClaims
可以自定义用户数据.
运行 example/server/server.go
在 8000
端口.
$ go run example/server/server.go
通过 httpie ,在命令行来测试下效果.
$ http -v --form POST localhost:8000/login username=admin password=admin
命令行输出
$ http -v -f GET localhost:8000/user/refresh_token "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
命令行输出
我们使用用户名 admin
和密码 admin
测试一下 hello 接口的返回
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
命令行输出
我们用未授权的 token 来测试 hello 接口的返回
$ http -f GET localhost:8000/user/hello "Authorization:Bearer xxxxxxxxx" "Content-Type: application/json"
命令行输出
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。