go-zero
go-zero copied to clipboard
feat: support multiple extract token key
Implement support for multiple custom token keys and simplify the JWT authentication configuration. WithTokenLookups
function enables setting token keys, improving the authentication process by accommodating various token header extraction strategies. by accommodating various token header extraction strategies.
example:
jwt-api.api
syntax = "v1"
type Request {
Name string `path:"name,options=you|me"`
}
type Response {
Message string `json:"message"`
}
type FormExampleReq {
Name string `form:"name,options=you|me"`
}
@server(
jwt: Auth
jwtTransition: Trans
)
service A-api {
@handler GreetHandler
get /greet/from/:name(Request) returns (Response)
@handler FormExample
post /form/example (FormExampleReq) returns (Response)
}
a-api.yaml
Name: A-api
Host: 0.0.0.0
Port: 8888
Auth:
AccessSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AccessExpire: 604800
TokenLookup:
- "header:Token"
- "query:Token"
- "form:Token"
Trans:
Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PrevSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TokenLookup:
- "header:Token"
- "query:Token"
- "form:Token"
TokenLookup
extract a jwt from custom request header or post form or get url arguments.