gin-jwt
1. Authenticator 回傳的 data
2. data 會丟入到 PayloadFunc
3. PayloadFunc 整理資料寫入 MapClaims
4. Authorizator 再拿 MapClaims 資料出來判斷
新版和舊版有地方不同
type xxxxx struct{
aaaaaaa:string
}
1、
Authenticator: func(userId string, password string, c *gin.Context) (interface{}, bool) {
return xxxxx{aaaaaaa: ooooxxxx} or string
2、
PayloadFunc: func(data interface{}) jwt.MapClaims {
if v, ok := data.(xxxxx); ok {
id = data.(xxxxx).aaaaaaa
}
return jwt.MapClaims{“aaaaaaa”: ooooxxxx, “bbbbbbb”: ooooxxxx}
3、
Authorizator: func(data interface{}, c *gin.Context) bool {
claims := jwt.ExtractClaims(c)
id := claims[“aaaaaaa”].(string)
!注意! Here data is string fmt.Println(reflect.TypeOf(data))