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
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
9 years ago
by
Rohith
Browse files
Options
Downloads
Patches
Plain Diff
- adding the clean up session methods
parent
960f450f
No related branches found
No related tags found
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.
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
)
{
// step: parse and return the token
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
// 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
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
register
or
sign in
to comment