return 401 for invalid token
This commit is contained in:
parent
346a310eb6
commit
1ac37b048f
6 changed files with 14 additions and 14 deletions
|
|
@ -41,7 +41,7 @@ func JwtValidate(tokenString string, secret ...[]byte) *JwtClaims {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("JWT ParseWithClaims Error: %s", err)
|
log.Error("JWT ParseWithClaims Error: %s", err)
|
||||||
exception.New("Invalid token", 403).Ctx(err.Error()).Throw()
|
exception.New("Invalid token", 401).Ctx(err.Error()).Throw()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ func JwtValidate(tokenString string, secret ...[]byte) *JwtClaims {
|
||||||
return claims
|
return claims
|
||||||
}
|
}
|
||||||
|
|
||||||
exception.New("Invalid token", 403).Ctx(token.Claims).Throw()
|
exception.New("Invalid token", 401).Ctx(token.Claims).Throw()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func hdAuth(c *gin.Context) {
|
||||||
if strings.HasPrefix(tokenString, "Bearer") {
|
if strings.HasPrefix(tokenString, "Bearer") {
|
||||||
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
c.JSON(401, gin.H{"code": 401, "message": "Not authenticated"})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,15 @@ var Guards = map[string]func(c *Request) error{
|
||||||
// JWT Bearer JWT
|
// JWT Bearer JWT
|
||||||
func guardBearerJWT(r *Request) error {
|
func guardBearerJWT(r *Request) error {
|
||||||
if r.context == nil {
|
if r.context == nil {
|
||||||
return fmt.Errorf("No permission")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
c := r.context
|
c := r.context
|
||||||
tokenString := c.Request.Header.Get("Authorization")
|
tokenString := c.Request.Header.Get("Authorization")
|
||||||
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
c.JSON(401, gin.H{"code": 401, "message": "Not authenticated"})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return fmt.Errorf("No permission")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
|
|
||||||
claims := helper.JwtValidate(tokenString)
|
claims := helper.JwtValidate(tokenString)
|
||||||
|
|
@ -56,13 +56,13 @@ func guardCookieJWT(r *Request) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
// c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
||||||
// c.Abort()
|
// c.Abort()
|
||||||
return fmt.Errorf("Not Authorized")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
|
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
// c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
// c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
||||||
// c.Abort()
|
// c.Abort()
|
||||||
return fmt.Errorf("Not Authorized")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
|
|
||||||
claims := helper.JwtValidate(tokenString)
|
claims := helper.JwtValidate(tokenString)
|
||||||
|
|
@ -93,15 +93,15 @@ func guardCookieTrace(r *Request) error {
|
||||||
// JWT Bearer JWT
|
// JWT Bearer JWT
|
||||||
func guardQueryJWT(r *Request) error {
|
func guardQueryJWT(r *Request) error {
|
||||||
if r.context == nil {
|
if r.context == nil {
|
||||||
return fmt.Errorf("No permission")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
c := r.context
|
c := r.context
|
||||||
|
|
||||||
tokenString := c.Query("__tk")
|
tokenString := c.Query("__tk")
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
c.JSON(403, gin.H{"code": 403, "message": "No permission"})
|
c.JSON(401, gin.H{"code": 401, "message": "Not authenticated"})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return fmt.Errorf("No permission")
|
return fmt.Errorf("Not authenticated")
|
||||||
}
|
}
|
||||||
|
|
||||||
claims := helper.JwtValidate(tokenString)
|
claims := helper.JwtValidate(tokenString)
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ func processDownload(process *gouProcess.Process) interface{} {
|
||||||
// Auth
|
// Auth
|
||||||
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
exception.New("%s.%s No permission", 403, form.ID, field).Throw()
|
exception.New("%s.%s not authenticated", 401, form.ID, field).Throw()
|
||||||
}
|
}
|
||||||
claims := helper.JwtValidate(tokenString)
|
claims := helper.JwtValidate(tokenString)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func processDownload(process *gouProcess.Process) interface{} {
|
||||||
// Auth
|
// Auth
|
||||||
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
exception.New("%s.%s No permission", 403, list.ID, field).Throw()
|
exception.New("%s.%s not authenticated", 401, list.ID, field).Throw()
|
||||||
}
|
}
|
||||||
claims := helper.JwtValidate(tokenString)
|
claims := helper.JwtValidate(tokenString)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func processLoginAdmin(process *process.Process) interface{} {
|
||||||
|
|
||||||
if !helper.CaptchaValidate(id, value) {
|
if !helper.CaptchaValidate(id, value) {
|
||||||
log.With(log.F{"id": id, "code": value}).Debug("ProcessLogin")
|
log.With(log.F{"id": id, "code": value}).Debug("ProcessLogin")
|
||||||
exception.New("验证码不正确", 403).Ctx(maps.Map{"id": id, "code": value}).Throw()
|
exception.New("验证码不正确", 401).Ctx(maps.Map{"id": id, "code": value}).Throw()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue