Skip to content

Commit

Permalink
fix(auth): fix logout handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Feb 4, 2019
1 parent ce010de commit 79f5d2a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/gorilla/sessions"
"github.com/labstack/echo"
Expand Down Expand Up @@ -86,7 +87,11 @@ func (o *OAuth) LoginHandler() func(echo.Context) error {

sess, err := session.Get("state", c)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
c.Logger().Warn("invalid session: ", err.Error())
}

if sess == nil {
return echo.NewHTTPError(http.StatusInternalServerError, "invalid session")
}

b := make([]byte, 32)
Expand All @@ -113,14 +118,19 @@ func (o *OAuth) LogoutHandler(redirectUrl string) func(echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

cookie, err := c.Cookie("auth-session")
if err == nil {
cookie.Value = ""
cookie.MaxAge = -1 // erase the cookie
c.SetCookie(cookie)

} else {
c.Logger().Warn("tryin to logout with no cookie set")
for _, ck := range []string{"auth-session", "state"} {
cookie, err := c.Cookie(ck)
if err == nil {
cookie.MaxAge = -1 // erase the cookie
cookie.Value = ""
cookie.Path = "/"
cookie.Expires = time.Unix(0, 0)
cookie.HttpOnly = true
c.SetCookie(cookie)

} else {
c.Logger().Warn("tryin to logout with no cookie set")
}
}

logoutUrl.Path += "/v2/logout"
Expand Down

0 comments on commit 79f5d2a

Please sign in to comment.