Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
hdacloud
dex
Commits
575c7921
Unverified
Commit
575c7921
authored
7 years ago
by
Joel Speed
Browse files
Options
Downloads
Patches
Plain Diff
Store most recent refresh token in offline sessions
parent
c392236f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/handlers.go
+33
-0
33 additions, 0 deletions
server/handlers.go
storage/storage.go
+3
-0
3 additions, 0 deletions
storage/storage.go
with
36 additions
and
0 deletions
server/handlers.go
+
33
−
0
View file @
575c7921
...
@@ -505,6 +505,39 @@ func (s *Server) finalizeLogin(identity connector.Identity, authReq storage.Auth
...
@@ -505,6 +505,39 @@ func (s *Server) finalizeLogin(identity connector.Identity, authReq storage.Auth
s
.
logger
.
Infof
(
"login successful: connector %q, username=%q, preferred_username=%q, email=%q, groups=%q"
,
s
.
logger
.
Infof
(
"login successful: connector %q, username=%q, preferred_username=%q, email=%q, groups=%q"
,
authReq
.
ConnectorID
,
claims
.
Username
,
claims
.
PreferredUsername
,
email
,
claims
.
Groups
)
authReq
.
ConnectorID
,
claims
.
Username
,
claims
.
PreferredUsername
,
email
,
claims
.
Groups
)
if
_
,
ok
:=
conn
.
(
connector
.
RefreshConnector
);
ok
{
// Try to retrieve an existing OfflineSession object for the corresponding user.
if
session
,
err
:=
s
.
storage
.
GetOfflineSessions
(
identity
.
UserID
,
authReq
.
ConnectorID
);
err
!=
nil
{
if
err
!=
storage
.
ErrNotFound
{
s
.
logger
.
Errorf
(
"failed to get offline session: %v"
,
err
)
return
""
,
err
}
offlineSessions
:=
storage
.
OfflineSessions
{
UserID
:
identity
.
UserID
,
ConnID
:
authReq
.
ConnectorID
,
Refresh
:
make
(
map
[
string
]
*
storage
.
RefreshTokenRef
),
ConnectorData
:
identity
.
ConnectorData
,
}
// Create a new OfflineSession object for the user and add a reference object for
// the newly received refreshtoken.
if
err
:=
s
.
storage
.
CreateOfflineSessions
(
offlineSessions
);
err
!=
nil
{
s
.
logger
.
Errorf
(
"failed to create offline session: %v"
,
err
)
return
""
,
err
}
}
else
{
// Update existing OfflineSession obj with new RefreshTokenRef.
if
err
:=
s
.
storage
.
UpdateOfflineSessions
(
session
.
UserID
,
session
.
ConnID
,
func
(
old
storage
.
OfflineSessions
)
(
storage
.
OfflineSessions
,
error
)
{
old
.
ConnectorData
=
identity
.
ConnectorData
return
old
,
nil
});
err
!=
nil
{
s
.
logger
.
Errorf
(
"failed to update offline session: %v"
,
err
)
return
""
,
err
}
}
}
return
path
.
Join
(
s
.
issuerURL
.
Path
,
"/approval"
)
+
"?req="
+
authReq
.
ID
,
nil
return
path
.
Join
(
s
.
issuerURL
.
Path
,
"/approval"
)
+
"?req="
+
authReq
.
ID
,
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
storage/storage.go
+
3
−
0
View file @
575c7921
...
@@ -273,6 +273,9 @@ type OfflineSessions struct {
...
@@ -273,6 +273,9 @@ type OfflineSessions struct {
// Refresh is a hash table of refresh token reference objects
// Refresh is a hash table of refresh token reference objects
// indexed by the ClientID of the refresh token.
// indexed by the ClientID of the refresh token.
Refresh
map
[
string
]
*
RefreshTokenRef
Refresh
map
[
string
]
*
RefreshTokenRef
// Authentication data provided by an upstream source.
ConnectorData
[]
byte
}
}
// Password is an email to password mapping managed by the storage.
// Password is an email to password mapping managed by the storage.
...
...
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