Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var JWT = &jwt.GinJWTMiddleware{ Realm: "si-engine", Key: []byte("RGV05HJoZWx0b3Ryb2xpZ3R2aWxrZXRzduVydGz2c2Vub3JkZGV0dGHkcg=="), Timeout: time.Hour * 24 * 365 * 30, MaxRefresh: time.Hour, IdentityKey: identityKey, PayloadFunc: func(data interface{}) jwt.MapClaims { if v, ok := data.(*db.User); ok { return jwt.MapClaims{ identityKey: v.UserName, } } return jwt.MapClaims{} }, IdentityHandler: func(c *gin.Context) interface{} { claims := jwt.ExtractClaims(c) return &db.User{ UserName: claims[identityKey].(string), } }, Authenticator: func(c *gin.Context) (interface{}, error) { var loginVals login if err := c.ShouldBind(&loginVals); err != nil { return "", jwt.ErrMissingLoginValues } userID := loginVals.Username password := loginVals.Password // TODO: save salted and hashed passwords rather than plain text var user db.User result := db.DB.Where("user_name = ? and password = ?", userID, password).First(&user) if result.Error != nil { return nil, jwt.ErrFailedAuthentication } return &user, nil }, Authorizator: func(data interface{}, c *gin.Context) bool { if v, ok := data.(*db.User); ok && v.UserName == "admin@acme.com" { return true } return true }, Unauthorized: func(c *gin.Context, code int, message string) { c.JSON(code, gin.H{ "code": code, "message": message, }) }, TokenLookup: "header: Authorization", TokenHeadName: "Bearer", TimeFunc: time.Now, }
Functions ¶
func Run ¶
func Run(broker *usvc.UsvcBroker)
Types ¶
Click to show internal directories.
Click to hide internal directories.