Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keycloak-proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
keycloak-proxy
Commits
6356a837
Commit
6356a837
authored
Dec 14, 2015
by
Rohith
Browse files
Options
Downloads
Patches
Plain Diff
- adding the clean up session methods
parent
960f450f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
oauth.go
+1
-1
1 addition, 1 deletion
oauth.go
session.go
+14
-2
14 additions, 2 deletions
session.go
with
15 additions
and
3 deletions
oauth.go
+
1
−
1
View file @
6356a837
...
@@ -158,7 +158,7 @@ func (r *KeycloakProxy) refreshAccessToken(refreshToken string) (jose.JWT, time.
...
@@ -158,7 +158,7 @@ func (r *KeycloakProxy) refreshAccessToken(refreshToken string) (jose.JWT, time.
return
token
,
identity
.
ExpiresAt
,
nil
return
token
,
identity
.
ExpiresAt
,
nil
}
}
// parse
Access
Token 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
)
{
func
(
r
*
KeycloakProxy
)
parseToken
(
accessToken
string
)
(
jose
.
JWT
,
*
oidc
.
Identity
,
error
)
{
// step: parse and return the token
// step: parse and return the token
token
,
err
:=
jose
.
ParseJWT
(
accessToken
)
token
,
err
:=
jose
.
ParseJWT
(
accessToken
)
...
...
...
...
This diff is collapsed.
Click to expand it.
session.go
+
14
−
2
View file @
6356a837
...
@@ -49,7 +49,8 @@ func (r *KeycloakProxy) refreshUserSessionToken(cx *gin.Context) (jose.JWT, erro
...
@@ -49,7 +49,8 @@ func (r *KeycloakProxy) refreshUserSessionToken(cx *gin.Context) (jose.JWT, erro
// step: has the refresh token expired
// step: has the refresh token expired
if
err
==
ErrRefreshTokenExpired
{
if
err
==
ErrRefreshTokenExpired
{
glog
.
Warningf
(
"the refresh token has expired: %s"
,
token
)
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
)
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
...
@@ -59,6 +60,7 @@ func (r *KeycloakProxy) refreshUserSessionToken(cx *gin.Context) (jose.JWT, erro
// step: inject the refreshed access token
// step: inject the refreshed access token
glog
.
V
(
10
)
.
Infof
(
"injecting the refreshed access token into seesion, expires on: %s"
,
expires
)
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
{
if
err
:=
r
.
createSession
(
token
,
expires
,
cx
);
err
!=
nil
{
return
token
,
err
return
token
,
err
}
}
...
@@ -95,7 +97,6 @@ func (r *KeycloakProxy) getSessionState(cx *gin.Context) (*SessionState, error)
...
@@ -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
// 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
)
{
func
(
r
*
KeycloakProxy
)
getUserContext
(
token
jose
.
JWT
)
(
*
UserContext
,
error
)
{
// step: decode the claims from the tokens
// step: decode the claims from the tokens
claims
,
err
:=
token
.
Claims
()
claims
,
err
:=
token
.
Claims
()
...
@@ -218,6 +219,7 @@ func createSessionCookie(token, hostname string, expires time.Time) *http.Cookie
...
@@ -218,6 +219,7 @@ func createSessionCookie(token, hostname string, expires time.Time) *http.Cookie
Path
:
"/"
,
Path
:
"/"
,
Expires
:
expires
,
Expires
:
expires
,
HttpOnly
:
true
,
HttpOnly
:
true
,
// Secure: true,
Value
:
token
,
Value
:
token
,
}
}
}
}
...
@@ -233,3 +235,13 @@ func createSessionStateCookie(token, hostname string, expires time.Time) *http.C
...
@@ -233,3 +235,13 @@ func createSessionStateCookie(token, hostname string, expires time.Time) *http.C
Value
:
token
,
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment