mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
e17b49e4ca
* feat: manage apple idp * handle apple idp callback * add tests for provider * basic console implementation * implement flow for login UI and add logos / styling * tests * cleanup * add upload button * begin i18n * apple logo positioning, file upload component * fix add apple instance idp * add missing apple logos for login * update to go 1.21 * fix slice compare * revert permission changes * concrete error messages * translate login apple logo -y-2px * change form parsing * sign in button * fix tests * lint console --------- Co-authored-by: peintnermax <max@caos.ch>
165 lines
3.9 KiB
Go
165 lines
3.9 KiB
Go
package idp
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
type AppleIDPAddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
ClientID string `json:"clientId"`
|
|
TeamID string `json:"teamId"`
|
|
KeyID string `json:"keyId"`
|
|
PrivateKey *crypto.CryptoValue `json:"privateKey"`
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
Options
|
|
}
|
|
|
|
func NewAppleIDPAddedEvent(
|
|
base *eventstore.BaseEvent,
|
|
id,
|
|
name,
|
|
clientID,
|
|
teamID,
|
|
keyID string,
|
|
privateKey *crypto.CryptoValue,
|
|
scopes []string,
|
|
options Options,
|
|
) *AppleIDPAddedEvent {
|
|
return &AppleIDPAddedEvent{
|
|
BaseEvent: *base,
|
|
ID: id,
|
|
Name: name,
|
|
ClientID: clientID,
|
|
TeamID: teamID,
|
|
KeyID: keyID,
|
|
PrivateKey: privateKey,
|
|
Scopes: scopes,
|
|
Options: options,
|
|
}
|
|
}
|
|
|
|
func (e *AppleIDPAddedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *AppleIDPAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func AppleIDPAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
e := &AppleIDPAddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "IDP-Beqss", "unable to unmarshal event")
|
|
}
|
|
|
|
return e, nil
|
|
}
|
|
|
|
type AppleIDPChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
ID string `json:"id"`
|
|
Name *string `json:"name,omitempty"`
|
|
ClientID *string `json:"clientId,omitempty"`
|
|
TeamID *string `json:"teamId,omitempty"`
|
|
KeyID *string `json:"keyId,omitempty"`
|
|
PrivateKey *crypto.CryptoValue `json:"privateKey,omitempty"`
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
OptionChanges
|
|
}
|
|
|
|
func NewAppleIDPChangedEvent(
|
|
base *eventstore.BaseEvent,
|
|
id string,
|
|
changes []AppleIDPChanges,
|
|
) (*AppleIDPChangedEvent, error) {
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "IDP-SF3h2", "Errors.NoChangesFound")
|
|
}
|
|
changedEvent := &AppleIDPChangedEvent{
|
|
BaseEvent: *base,
|
|
ID: id,
|
|
}
|
|
for _, change := range changes {
|
|
change(changedEvent)
|
|
}
|
|
return changedEvent, nil
|
|
}
|
|
|
|
type AppleIDPChanges func(*AppleIDPChangedEvent)
|
|
|
|
func ChangeAppleName(name string) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.Name = &name
|
|
}
|
|
}
|
|
|
|
func ChangeAppleClientID(clientID string) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.ClientID = &clientID
|
|
}
|
|
}
|
|
|
|
func ChangeAppleTeamID(teamID string) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.TeamID = &teamID
|
|
}
|
|
}
|
|
|
|
func ChangeAppleKeyID(keyID string) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.KeyID = &keyID
|
|
}
|
|
}
|
|
|
|
func ChangeApplePrivateKey(privateKey *crypto.CryptoValue) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.PrivateKey = privateKey
|
|
}
|
|
}
|
|
|
|
func ChangeAppleScopes(scopes []string) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.Scopes = scopes
|
|
}
|
|
}
|
|
|
|
func ChangeAppleOptions(options OptionChanges) func(*AppleIDPChangedEvent) {
|
|
return func(e *AppleIDPChangedEvent) {
|
|
e.OptionChanges = options
|
|
}
|
|
}
|
|
|
|
func (e *AppleIDPChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *AppleIDPChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func AppleIDPChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
e := &AppleIDPChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "IDP-NBe1s", "unable to unmarshal event")
|
|
}
|
|
|
|
return e, nil
|
|
}
|