(c *gin.Context)
| 311 | } |
| 312 | |
| 313 | func Logout(c *gin.Context) { |
| 314 | tokenString, err := c.Cookie("token") |
| 315 | if err != nil || len(tokenString) == 0 { |
| 316 | c.JSON(http.StatusOK, gin.H{"code": http.StatusUnauthorized}) |
| 317 | return |
| 318 | } |
| 319 | token, err := ValidateToken(tokenString) |
| 320 | if err != nil { |
| 321 | c.JSON(http.StatusOK, gin.H{"code": http.StatusBadRequest, "message": "token is valied"}) |
| 322 | return |
| 323 | } |
| 324 | if config.AuthType == "iam" { |
| 325 | if err = iamLogout(token); err != nil { |
| 326 | log.Println("iam logout failed", err) |
| 327 | c.JSON(http.StatusOK, gin.H{"code": http.StatusInternalServerError, "message": "iam logout failed"}) |
| 328 | return |
| 329 | } |
| 330 | } |
| 331 | c.SetCookie("token", "", -1, "/", "", false, true) |
| 332 | c.JSON(http.StatusOK, gin.H{"code": http.StatusUnauthorized, "link": "/", "message": "logout sucessfully"}) |
| 333 | } |
| 334 | |
| 335 | func iamLogout(token *jwt.Token) error { |
| 336 | claims := token.Claims.(jwt.MapClaims) |
nothing calls this directly
no test coverage detected