mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-27 22:27:23 +08:00
Rename identities table columns for more clarity. Rename parameters,
arguments etc. to accommodate these changes.
Change that the SAML provider domain is persisted in the identities
table as the provider ID. Use the SAML Entity ID/Issuer ID of the
IdP instead.
Introduce saml identity entity (including migrations and a persister)
as a specialization of an identity to allow for determining the
correct provider name to return to the client/frontend and for assisting
in determining whether an identity is a SAML identity (i.e. SAML
identities should have a corresponding SAML Identity instance while
OAuth/OIDC entities do not).
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package persistence
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gobuffalo/pop/v6"
|
|
"github.com/teamhanko/hanko/backend/persistence/models"
|
|
)
|
|
|
|
type SamlIdentityPersister interface {
|
|
Create(samlIdentity models.SamlIdentity) error
|
|
Update(samlIdentity models.SamlIdentity) error
|
|
}
|
|
|
|
type samlIdentityPersister struct {
|
|
db *pop.Connection
|
|
}
|
|
|
|
func NewSamlIdentityPersister(db *pop.Connection) SamlIdentityPersister {
|
|
return &samlIdentityPersister{db: db}
|
|
}
|
|
|
|
func (p samlIdentityPersister) Create(samlIdentity models.SamlIdentity) error {
|
|
vErr, err := p.db.Eager().ValidateAndCreate(&samlIdentity)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to store saml identity: %w", err)
|
|
}
|
|
|
|
if vErr != nil && vErr.HasAny() {
|
|
return fmt.Errorf("saml identity object validation failed: %w", vErr)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p samlIdentityPersister) Update(samlIdentity models.SamlIdentity) error {
|
|
vErr, err := p.db.ValidateAndUpdate(&samlIdentity)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to update saml identity: %w", err)
|
|
}
|
|
|
|
if vErr != nil && vErr.HasAny() {
|
|
return fmt.Errorf("saml identity object validation failed: %w", vErr)
|
|
}
|
|
|
|
return nil
|
|
}
|