mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: add ldap external idp to login api (#5938)
* fix: handling of ldap login through separate endpoint * fix: handling of ldap login through separate endpoint * fix: handling of ldap login through separate endpoint * fix: successful intent for ldap * fix: successful intent for ldap * fix: successful intent for ldap * fix: add changes from code review * fix: remove set intent credentials and handle ldap errors * fix: remove set intent credentials and handle ldap errors * refactor into separate methods and fix merge * remove mocks --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -7,5 +7,6 @@ import (
|
||||
func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
es.RegisterFilterEventMapper(AggregateType, StartedEventType, StartedEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, SucceededEventType, SucceededEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, LDAPSucceededEventType, LDAPSucceededEventMapper).
|
||||
RegisterFilterEventMapper(AggregateType, FailedEventType, FailedEventMapper)
|
||||
}
|
||||
|
@@ -12,9 +12,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
StartedEventType = instanceEventTypePrefix + "started"
|
||||
SucceededEventType = instanceEventTypePrefix + "succeeded"
|
||||
FailedEventType = instanceEventTypePrefix + "failed"
|
||||
StartedEventType = instanceEventTypePrefix + "started"
|
||||
SucceededEventType = instanceEventTypePrefix + "succeeded"
|
||||
LDAPSucceededEventType = instanceEventTypePrefix + "ldap.succeeded"
|
||||
FailedEventType = instanceEventTypePrefix + "failed"
|
||||
)
|
||||
|
||||
type StartedEvent struct {
|
||||
@@ -68,10 +69,11 @@ func StartedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
type SucceededEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
IDPUser []byte `json:"idpUser"`
|
||||
IDPUserID string `json:"idpUserId,omitempty"`
|
||||
IDPUserName string `json:"idpUserName,omitempty"`
|
||||
UserID string `json:"userId,omitempty"`
|
||||
IDPUser []byte `json:"idpUser"`
|
||||
IDPUserID string `json:"idpUserId,omitempty"`
|
||||
IDPUserName string `json:"idpUserName,omitempty"`
|
||||
UserID string `json:"userId,omitempty"`
|
||||
|
||||
IDPAccessToken *crypto.CryptoValue `json:"idpAccessToken,omitempty"`
|
||||
IDPIDToken string `json:"idpIdToken,omitempty"`
|
||||
}
|
||||
@@ -122,6 +124,61 @@ func SucceededEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
return e, nil
|
||||
}
|
||||
|
||||
type LDAPSucceededEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
IDPUser []byte `json:"idpUser"`
|
||||
IDPUserID string `json:"idpUserId,omitempty"`
|
||||
IDPUserName string `json:"idpUserName,omitempty"`
|
||||
UserID string `json:"userId,omitempty"`
|
||||
|
||||
EntryAttributes map[string][]string `json:"user,omitempty"`
|
||||
}
|
||||
|
||||
func NewLDAPSucceededEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
idpUser []byte,
|
||||
idpUserID,
|
||||
idpUserName,
|
||||
userID string,
|
||||
attributes map[string][]string,
|
||||
) *LDAPSucceededEvent {
|
||||
return &LDAPSucceededEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
LDAPSucceededEventType,
|
||||
),
|
||||
IDPUser: idpUser,
|
||||
IDPUserID: idpUserID,
|
||||
IDPUserName: idpUserName,
|
||||
UserID: userID,
|
||||
EntryAttributes: attributes,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *LDAPSucceededEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *LDAPSucceededEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func LDAPSucceededEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &LDAPSucceededEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "IDP-HBreq", "unable to unmarshal event")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
type FailedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
|
Reference in New Issue
Block a user