mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-07 06:57:54 +00:00
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
config2 "go-admin/config"
|
|
"go-admin/handler"
|
|
jwt "go-admin/pkg/jwtauth"
|
|
"time"
|
|
)
|
|
|
|
func AuthInit() (*jwt.GinJWTMiddleware, error) {
|
|
// the jwt middleware
|
|
return jwt.New(&jwt.GinJWTMiddleware{
|
|
Realm: "test zone",
|
|
Key: []byte("secret key"),
|
|
Timeout: time.Hour,
|
|
MaxRefresh: time.Hour,
|
|
IdentityKey: config2.ApplicationConfig.JwtSecret,
|
|
PayloadFunc: handler.PayloadFunc,
|
|
IdentityHandler: handler.IdentityHandler,
|
|
Authenticator: handler.Authenticator,
|
|
Authorizator: handler.Authorizator,
|
|
Unauthorized: handler.Unauthorized,
|
|
// TokenLookup is a string in the form of "<source>:<name>" that is used
|
|
// to extract token from the request.
|
|
// Optional. Default value "header:Authorization".
|
|
// Possible values:
|
|
// - "header:<name>"
|
|
// - "query:<name>"
|
|
// - "cookie:<name>"
|
|
// - "param:<name>"
|
|
TokenLookup: "header: Authorization, query: token, cookie: jwt",
|
|
// TokenLookup: "query:token",
|
|
// TokenLookup: "cookie:token",
|
|
|
|
// TokenHeadName is a string in the header. Default value is "Bearer"
|
|
TokenHeadName: "Bearer",
|
|
|
|
// TimeFunc provides the current time. You can override it to use another time value. This is useful for testing or if your server uses a different time zone than your tokens.
|
|
TimeFunc: time.Now,
|
|
})
|
|
|
|
}
|