Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab5ea03

Browse files
committed
handlers: do not fail login if refresh token gone
There is a chance that offline storage could fall out of sync with the refresh token tables. One example is if dex crashes/is stopped in the middle of handling a login request. If the old refresh token associated with the offline session is deleted, and then the process stops, the offline session will still refer to the old token. Unfortunately, if this case occurs, there is no way to recover from it, since further logins will be halted due to dex being unable to clean up the old tokens till referenced in the offline session: the database is essentially corrupted. There doesn't seem to be a good reason to fail the auth request if the old refresh token is gone. This changes the logic in `handleAuthCode` to not fail the entire transaction if the old refresh token could not be deleted because it was not present. This has the effect of installing the new refresh token, and unpdating the offline storage, thereby fixing the issue, however it occured.
1 parent 2772725 commit ab5ea03

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

server/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ func (s *Server) handleAuthCode(w http.ResponseWriter, r *http.Request, client s
905905
} else {
906906
if oldTokenRef, ok := session.Refresh[tokenRef.ClientID]; ok {
907907
// Delete old refresh token from storage.
908-
if err := s.storage.DeleteRefresh(oldTokenRef.ID); err != nil {
908+
if err := s.storage.DeleteRefresh(oldTokenRef.ID); err != nil && err != storage.ErrNotFound {
909909
s.logger.Errorf("failed to delete refresh token: %v", err)
910910
s.tokenErrHelper(w, errServerError, "", http.StatusInternalServerError)
911911
deleteToken = true

0 commit comments

Comments
 (0)