(token string, ab backends.Authentication, secret []byte, exp int)
| 64 | } |
| 65 | |
| 66 | func IsJwtTokenValid(token string, ab backends.Authentication, secret []byte, exp int) bool { |
| 67 | authBackend := InitJWTAuthenticationBackend(ab, secret, exp) |
| 68 | |
| 69 | jwtToken, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { |
| 70 | if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { |
| 71 | return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) |
| 72 | } else { |
| 73 | return authBackend.SecretKey, nil |
| 74 | } |
| 75 | }) |
| 76 | |
| 77 | if err == nil && jwtToken.Valid && !authBackend.IsInBlacklist(token) { |
| 78 | return true |
| 79 | } else { |
| 80 | return false |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func RefreshToken(requestUser *backends.User, ab backends.Authentication, secret []byte, exp int) []byte { |
| 85 | authBackend := InitJWTAuthenticationBackend(ab, secret, exp) |
no test coverage detected