Unindent session updates on finalizeLogin

This commit is contained in:
Joel Speed 2019-09-25 21:27:31 +01:00
parent 77fcf9ad77
commit d9095073c8
No known key found for this signature in database
GPG key ID: 6E80578D6751DEFB

View file

@ -505,42 +505,45 @@ 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 { returnURL := path.Join(s.issuerURL.Path, "/approval") + "?req=" + authReq.ID
// Try to retrieve an existing OfflineSession object for the corresponding user. _, ok := conn.(connector.RefreshConnector)
if session, err := s.storage.GetOfflineSessions(identity.UserID, authReq.ConnectorID); err != nil { if !ok {
if err != storage.ErrNotFound { return returnURL, nil
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 // Try to retrieve an existing OfflineSession object for the corresponding user.
// the newly received refreshtoken. if session, err := s.storage.GetOfflineSessions(identity.UserID, authReq.ConnectorID); err != nil {
if err := s.storage.CreateOfflineSessions(offlineSessions); err != nil { if err != storage.ErrNotFound {
s.logger.Errorf("failed to create offline session: %v", err) s.logger.Errorf("failed to get offline session: %v", err)
return "", err return "", err
} }
} else { offlineSessions := storage.OfflineSessions{
// Update existing OfflineSession obj with new RefreshTokenRef. UserID: identity.UserID,
if err := s.storage.UpdateOfflineSessions(session.UserID, session.ConnID, func(old storage.OfflineSessions) (storage.OfflineSessions, error) { ConnID: authReq.ConnectorID,
if len(identity.ConnectorData) > 0 { Refresh: make(map[string]*storage.RefreshTokenRef),
old.ConnectorData = identity.ConnectorData ConnectorData: identity.ConnectorData,
} }
return old, nil
}); err != nil {
s.logger.Errorf("failed to update offline session: %v", err)
return "", err
}
// 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) {
if len(identity.ConnectorData) > 0 {
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 returnURL, nil
} }
func (s *Server) handleApproval(w http.ResponseWriter, r *http.Request) { func (s *Server) handleApproval(w http.ResponseWriter, r *http.Request) {