-
Notifications
You must be signed in to change notification settings - Fork 42
JWT Endpoint
YoyoFx edited this page Dec 9, 2020
·
3 revisions
使用Endpoints.UseJwt 可以为应用程序创建验证凭证Token.
func main() {
YoyoGo.CreateDefaultBuilder(func (rb router.IRouterBuilder) {
endpoints.UseJwt(rb)
}.Build().Run()
}
创建Token依赖配置节点 application.server.jwt 下: **secret ** , **expires ** 分别用于jwt的密钥和过期时间.
application:
name: demo
server:
# ........
jwt:
header: "Authorization"
secret: "12391JdeOW^%$#@"
prefix: "Bearer"
expires: 3
enable: true
POST: /auth/token
请求参数:
{
"id":"22" ,
"name":"yoyo"
}
{
"success": true,
"expires": 1597928060,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTc5MjgwNjAsImlzcyI6InlveW8iLCJ1aWQiOjIyLCJhZG1pbiI6ZmFsc2V9.KSuCDABBjxQuDW9OJI-Jx4AFkXVObJ1sUcDvbpGN54g"
}