소스 검색

cookie ruler

Paul 7 년 전
부모
커밋
226dde51d7
1개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 9
    1
      middleware/auth/auth.go

+ 9
- 1
middleware/auth/auth.go 파일 보기

53
 
53
 
54
 		if mapClaims, ok := token.Claims.(jwt.MapClaims); ok {
54
 		if mapClaims, ok := token.Claims.(jwt.MapClaims); ok {
55
 			if expired, ok := mapClaims[ctxRequestTokenExpired].(float64); ok {
55
 			if expired, ok := mapClaims[ctxRequestTokenExpired].(float64); ok {
56
-				if int64(expired) < time.Now().Unix() {
56
+				if expired == 0 {
57
+					// Only cookie is exists, check token expired. app expired by itself call logout when app exit
58
+					if _, err := ctx.Cookie(ctxRequestCookieAuthorization); err != nil {
59
+						ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
60
+						return
61
+					}
62
+				}
63
+
64
+				if expired < 0 || (int64(expired) < time.Now().Unix()) {
57
 					ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
65
 					ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
58
 					return
66
 					return
59
 				}
67
 				}