Skip to content

Commit

Permalink
feat: add hook calls for single connector (dexidp#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Palesandro committed Nov 9, 2023
1 parent 501e7d7 commit 579bf92
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return
}

connObj, err := s.storage.GetConnector(connID)
if err != nil {
s.logger.Errorf("Failed to get connector: %v", err)
s.renderError(r, w, http.StatusBadRequest, "Requested resource does not exist")
return
}

s.logger.Infof("Connector Validation: %s", connID)
s.logger.Infof("Invoking %d hooks to filter connectors", len(s.connectorWebhookFilter))
filteredConnectors := []storage.Connector{connObj}
for _, c := range s.connectorWebhookFilter {
s.logger.Infof("Calling connectors webhook %s", c.Name)
filteredConnectors, err = c.FilterInvoker.CallHook(filteredConnectors, r)
if err != nil {
s.logger.Errorf("Failed to filter connectors: %v", err)
s.renderError(r, w, http.StatusInternalServerError, "Failed to retrieve connector list.")
return
}
s.logger.Infof("Connectors after webhook %s: %d", c.Name, len(filteredConnectors))
}

if len(filteredConnectors) == 0 {
s.logger.Errorf("Connector %s not valid for the current request", connID)
s.renderError(r, w, http.StatusBadRequest, "Invalid Request")
return
}

// Set the connector being used for the login.
if authReq.ConnectorID != "" && authReq.ConnectorID != connID {
s.logger.Errorf("Mismatched connector ID in auth request: %s vs %s",
Expand Down

0 comments on commit 579bf92

Please sign in to comment.