Skip to content
Snippets Groups Projects
Commit 6356a837 authored by Rohith's avatar Rohith
Browse files

- adding the clean up session methods

parent 960f450f
No related branches found
No related tags found
No related merge requests found
......@@ -158,7 +158,7 @@ func (r *KeycloakProxy) refreshAccessToken(refreshToken string) (jose.JWT, time.
return token, identity.ExpiresAt, nil
}
// parseAccessToken retrieve the user identity from the token
// parseToken retrieve the user identity from the token
func (r *KeycloakProxy) parseToken(accessToken string) (jose.JWT, *oidc.Identity, error) {
// step: parse and return the token
token, err := jose.ParseJWT(accessToken)
......
......@@ -49,7 +49,8 @@ func (r *KeycloakProxy) refreshUserSessionToken(cx *gin.Context) (jose.JWT, erro
// step: has the refresh token expired
if err == ErrRefreshTokenExpired {
glog.Warningf("the refresh token has expired: %s", token)
http.SetCookie(cx.Writer, createSessionStateCookie(token.Encode(), cx.Request.Host, time.Now()))
// clear the session
clearSessionState(cx)
}
glog.Errorf("failed to refresh the access token, reason: %s", err)
......@@ -59,6 +60,7 @@ func (r *KeycloakProxy) refreshUserSessionToken(cx *gin.Context) (jose.JWT, erro
// step: inject the refreshed access token
glog.V(10).Infof("injecting the refreshed access token into seesion, expires on: %s", expires)
// step: create the session
if err := r.createSession(token, expires, cx); err != nil {
return token, err
}
......@@ -95,7 +97,6 @@ func (r *KeycloakProxy) getSessionState(cx *gin.Context) (*SessionState, error)
}
// getUserContext parse the jwt token and extracts the various elements is order to construct
// a UserContext for use
func (r *KeycloakProxy) getUserContext(token jose.JWT) (*UserContext, error) {
// step: decode the claims from the tokens
claims, err := token.Claims()
......@@ -218,6 +219,7 @@ func createSessionCookie(token, hostname string, expires time.Time) *http.Cookie
Path: "/",
Expires: expires,
HttpOnly: true,
// Secure: true,
Value: token,
}
}
......@@ -233,3 +235,13 @@ func createSessionStateCookie(token, hostname string, expires time.Time) *http.C
Value: token,
}
}
// clearSessionState clears the session cookie
func clearSessionState(cx *gin.Context) {
http.SetCookie(cx.Writer, createSessionStateCookie("", cx.Request.Host, time.Now()))
}
// clearSession clears the session cookie
func clearSession(cx *gin.Context) {
http.SetCookie(cx.Writer, createSessionCookie("", cx.Request.Host, time.Now()))
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment