dto

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomClaimsFromUserModel added in v3.1.0

func CustomClaimsFromUserModel(customClaims *models.UserCustomClaims) json.RawMessage

CustomClaimsFromUserModel returns the flat {claimName: value} JSON view of a user's stored custom claims for JWT template processing (see UserJWT.CustomClaims), unwrapping the stored {claimName: {value, source}} envelope - source is internal bookkeeping (thirdparty.applyCustomClaims's source-scoped clear semantics) and must never reach the JWT. Returns nil if the user has no custom claims at all.

func NewHTTPErrorHandler

func NewHTTPErrorHandler(config HTTPErrorHandlerConfig) func(err error, c echo.Context)

func ToHttpError

func ToHttpError(err error) *echo.HTTPError

func TransformValidationErrors

func TransformValidationErrors(err error) []string

Types

type Claims

type Claims struct {
	Subject      uuid.UUID              `json:"subject"`
	IssuedAt     *time.Time             `json:"issued_at,omitempty"`
	Expiration   time.Time              `json:"expiration"`
	Audience     []string               `json:"audience,omitempty"`
	Issuer       *string                `json:"issuer,omitempty"`
	Email        *EmailJWT              `json:"email,omitempty"`
	Username     *string                `json:"username,omitempty"`
	SessionID    uuid.UUID              `json:"session_id"`
	CustomClaims map[string]interface{} `json:"-"`
}

func GetClaimsFromToken

func GetClaimsFromToken(token jwt.Token) (*Claims, error)

func (Claims) MarshalJSON

func (c Claims) MarshalJSON() ([]byte, error)

Custom MarshalJSON to flatten CustomClaims into the top level

type CreateSamlProviderRequest

type CreateSamlProviderRequest struct {
	Name                  string               `json:"name" validate:"required"`
	MetadataURL           string               `json:"metadata_url" validate:"required,url"`
	Domain                string               `json:"domain" validate:"required"`
	Enabled               bool                 `json:"enabled"`
	SkipEmailVerification bool                 `json:"skip_email_verification"`
	AttributeMap          *config.AttributeMap `json:"attribute_map,omitempty"`
}

CreateSamlProviderRequest represents the request body for creating a SAML provider

type CreateUserResponse

type CreateUserResponse struct {
	ID      uuid.UUID `json:"id"` // deprecated
	UserID  uuid.UUID `json:"user_id"`
	EmailID uuid.UUID `json:"email_id"`
}

type CustomValidator

type CustomValidator struct {
	Validator *validator.Validate
}

func NewCustomValidator

func NewCustomValidator() *CustomValidator

func (*CustomValidator) Validate

func (cv *CustomValidator) Validate(i interface{}) error

type EmailCreateRequest

type EmailCreateRequest struct {
	Address string `json:"address"`
}

type EmailJWT

type EmailJWT struct {
	Address    string `json:"address"`
	IsPrimary  bool   `json:"is_primary"`
	IsVerified bool   `json:"is_verified"`
}

func EmailJWTFromEmailModel

func EmailJWTFromEmailModel(email *models.Email) *EmailJWT

func (*EmailJWT) String

func (e *EmailJWT) String() string

type EmailResponse

type EmailResponse struct {
	ID         uuid.UUID  `json:"id"`
	Address    string     `json:"address"`
	IsVerified bool       `json:"is_verified"`
	IsPrimary  bool       `json:"is_primary"`
	Identity   *Identity  `json:"identity,omitempty"`   // Deprecated
	Identities Identities `json:"identities,omitempty"` // Deprecated. Identities are now accessible at the user level.
}

func FromEmailModel

func FromEmailModel(email *models.Email, cfg *config.TenantConfig) *EmailResponse

FromEmailModel Converts the DB model to a DTO object

type EmailUpdateRequest

type EmailUpdateRequest struct {
	IsPrimary *bool `json:"is_primary"`
}

type GetUserResponse

type GetUserResponse struct {
	ID                  uuid.UUID                   `json:"id"`
	Email               *string                     `json:"email,omitempty"`
	Username            *string                     `json:"username,omitempty"`
	WebauthnCredentials []models.WebauthnCredential `json:"webauthn_credentials"` // deprecated
	UpdatedAt           time.Time                   `json:"updated_at"`
	CreatedAt           time.Time                   `json:"created_at"`
	Metadata            *Metadata                   `json:"metadata,omitempty"`
	ProfileData         `json:",inline"`
}

type HTTPErrorHandlerConfig

type HTTPErrorHandlerConfig struct {
	Debug  bool
	Logger echo.Logger
}

type Identities

type Identities []Identity

func FromIdentitiesModel

func FromIdentitiesModel(identities models.Identities, cfg *config.TenantConfig) Identities

type Identity

type Identity struct {
	ID         string    `json:"id"` // the user/subject ID at the provider, ProviderUserID from models.Identity
	Provider   string    `json:"provider"`
	IdentityID uuid.UUID `json:"identity_id"` // the internal id from models.Identity
}

func FromIdentityModel

func FromIdentityModel(identity *models.Identity, cfg *config.TenantConfig) *Identity

type MFAConfig

type MFAConfig struct {
	AuthAppSetUp        bool `json:"auth_app_set_up"`
	TOTPEnabled         bool `json:"totp_enabled"`
	SecurityKeysEnabled bool `json:"security_keys_enabled"`
}

type Metadata

type Metadata struct {
	Public json.RawMessage `json:"public_metadata,omitempty"`
	Unsafe json.RawMessage `json:"unsafe_metadata,omitempty"`
}

Metadata represents user metadata with public and unsafe fields

func NewMetadata

func NewMetadata(metadata *models.UserMetadata) *Metadata

NewMetadata creates a new Metadata DTO from a UserMetadata model

type MetadataJWT

type MetadataJWT struct {
	// contains filtered or unexported fields
}

MetadataJWT represents user metadata with public and unsafe fields. This metadata representation is used for JWT template processing. Fields are private on purpose since the type provides dedicated methods with the same name for accessing the data during template processing.

func MetadataJWTFromUserModel

func MetadataJWTFromUserModel(metadata *models.UserMetadata) *MetadataJWT

MetadataJWTFromUserModel creates a new MetadataJWT DTO from a UserMetadata model

func NewMetadataJWT

func NewMetadataJWT(public, unsafe json.RawMessage) *MetadataJWT

NewMetadataJWT creates a new MetadataJWT from public and unsafe metadata JSON raw messages. Primarily used in tests to construct a MetadataJWT (due to private fields)

func (*MetadataJWT) MarshalJSON

func (m *MetadataJWT) MarshalJSON() ([]byte, error)

func (*MetadataJWT) Public

func (m *MetadataJWT) Public(path ...string) string

func (*MetadataJWT) String

func (m *MetadataJWT) String() string

func (*MetadataJWT) Unsafe

func (m *MetadataJWT) Unsafe(path ...string) string

type OptionalString added in v3.1.0

type OptionalString struct {
	Present bool
	Value   *string
}

OptionalString represents a PATCH-able string field with 3 states: - not present in JSON => Present=false (no change) - present with string => Present=true, Value!=nil (set) - present with null => Present=true, Value==nil (clear)

func (*OptionalString) UnmarshalJSON added in v3.1.0

func (o *OptionalString) UnmarshalJSON(b []byte) error

type PasscodeFinishRequest

type PasscodeFinishRequest struct {
	Id   string `json:"id" validate:"required,uuid4"`
	Code string `json:"code" validate:"required"`
}

type PasscodeInitRequest

type PasscodeInitRequest struct {
	UserId  string  `json:"user_id" validate:"required,uuid"`
	EmailId *string `json:"email_id"`
}

type PasscodeReturn

type PasscodeReturn struct {
	Id        string    `json:"id"`
	TTL       int       `json:"ttl"`
	CreatedAt time.Time `json:"created_at"`
}

type ProfileData

type ProfileData struct {
	// Added for backward compatibility, since ProfileData is now returned
	// in the '/me' endpoint, which previously  returned the user ID as `id`.
	ID           uuid.UUID                    `json:"id"`
	UserID       uuid.UUID                    `json:"user_id"`
	Passkeys     []WebauthnCredentialResponse `json:"passkeys,omitempty"`
	SecurityKeys []WebauthnCredentialResponse `json:"security_keys,omitempty"`
	MFAConfig    MFAConfig                    `json:"mfa_config"`
	Emails       []EmailResponse              `json:"emails,omitempty"`
	Username     *Username                    `json:"username,omitempty"`
	CreatedAt    time.Time                    `json:"created_at"`
	UpdatedAt    time.Time                    `json:"updated_at"`
	Metadata     *Metadata                    `json:"metadata,omitempty"`
	Identities   Identities                   `json:"identities,omitempty"`
	Name         string                       `json:"name,omitempty"`
	GivenName    string                       `json:"given_name,omitempty"`
	FamilyName   string                       `json:"family_name,omitempty"`
	Picture      string                       `json:"picture,omitempty"`
}

func ProfileDataFromUserModel

func ProfileDataFromUserModel(user *models.User, cfg *config.TenantConfig) *ProfileData

type RenewSamlCertificateRequest added in v3.2.0

type RenewSamlCertificateRequest struct {
	// KeyBits is the RSA key size. Without it the current key is kept; a size other than the current one
	// generates a new key pair.
	KeyBits *int `json:"key_bits"`
	// ValidityYears is the validity of the renewed certificate in whole years, defaults to 10.
	ValidityYears *int `json:"validity_years"`
	// RotateKey generates a new key pair even if the key size stays the same.
	RotateKey bool `json:"rotate_key"`
}

RenewSamlCertificateRequest customizes the renewal of a SAML certificate. All fields are optional.

type RoleCheckRequest added in v3.1.0

type RoleCheckRequest struct {
	OrganizationID uuid.UUID `json:"organization_id" validate:"required"`
	Roles          []string  `json:"roles" validate:"required,min=1"`
}

RoleCheckRequest.Roles entries may reference a role by either its id or its slug - resolved via RolePersister.GetByIDOrSlug.

type RoleCheckResponse added in v3.1.0

type RoleCheckResponse struct {
	HasRole bool `json:"has_role"`
}

type SamlAuthRequest

type SamlAuthRequest struct {
	SamlRequest
	RedirectTo string `query:"redirect_to" validate:"required,url"`
}

type SamlCertificateResponse added in v3.2.0

type SamlCertificateResponse struct {
	NotBefore time.Time `json:"not_before"`
	NotAfter  time.Time `json:"not_after"`
	KeyBits   int       `json:"key_bits"`
	// KeyChanged reports whether a new key pair was generated, in which case identity providers need the new
	// certificate before encrypted logins work again.
	KeyChanged bool `json:"key_changed"`
}

type SamlMetadataRequest

type SamlMetadataRequest struct {
	CertOnly bool `query:"cert_only" validate:"boolean"`
}

type SamlProviderResponse

type SamlProviderResponse struct {
	ID                    string               `json:"id"`
	TenantID              string               `json:"tenant_id"`
	Name                  string               `json:"name"`
	EntityID              string               `json:"entity_id"`
	MetadataURL           string               `json:"metadata_url"`
	Domain                string               `json:"domain"`
	Enabled               bool                 `json:"enabled"`
	SkipEmailVerification bool                 `json:"skip_email_verification"`
	AttributeMap          *config.AttributeMap `json:"attribute_map,omitempty"`
	CreatedAt             string               `json:"created_at"`
	UpdatedAt             string               `json:"updated_at"`
}

SamlProviderResponse represents the response for a SAML provider

func FromSamlProvider

func FromSamlProvider(provider *models.SamlProvider) SamlProviderResponse

type SamlProviderResponses

type SamlProviderResponses []SamlProviderResponse

func FromSamlProviders

func FromSamlProviders(providers []models.SamlProvider) SamlProviderResponses

type SamlRequest

type SamlRequest struct {
	Domain string `query:"domain" validate:"required,fqdn"`
}

type SessionData

type SessionData struct {
	ID           uuid.UUID  `json:"id"`
	UserAgentRaw *string    `json:"user_agent_raw,omitempty"`
	UserAgent    *string    `json:"user_agent,omitempty"`
	IpAddress    *string    `json:"ip_address,omitempty"`
	Current      bool       `json:"current"`
	CreatedAt    time.Time  `json:"created_at"`
	ExpiresAt    *time.Time `json:"expires_at,omitempty"`
	LastUsed     time.Time  `json:"last_used"`
}

func FromSessionModel

func FromSessionModel(model models.Session, current bool) SessionData

type ThirdPartyAuthCallback

type ThirdPartyAuthCallback struct {
	AuthCode         string `query:"code"`
	State            string `query:"state" validate:"required"`
	Error            string `query:"error"`
	ErrorDescription string `query:"error_description"`
}

func (ThirdPartyAuthCallback) HasError

func (cb ThirdPartyAuthCallback) HasError() bool

type ThirdPartyAuthRequest

type ThirdPartyAuthRequest struct {
	Provider   string `query:"provider" validate:"required"`
	RedirectTo string `query:"redirect_to" validate:"required,url"`
}

type UpdateSamlProviderRequest

type UpdateSamlProviderRequest struct {
	Name                  string               `json:"name" validate:"required"`
	MetadataURL           string               `json:"metadata_url" validate:"required,url"`
	Domain                string               `json:"domain" validate:"required"`
	Enabled               bool                 `json:"enabled"`
	SkipEmailVerification bool                 `json:"skip_email_verification"`
	AttributeMap          *config.AttributeMap `json:"attribute_map,omitempty"`
}

UpdateSamlProviderRequest represents the request body for updating a SAML provider

type UserInfoResponse

type UserInfoResponse struct {
	ID                    uuid.UUID `json:"id"`
	EmailID               uuid.UUID `json:"email_id"`
	Verified              bool      `json:"verified"`
	HasWebauthnCredential bool      `json:"has_webauthn_credential"`
}

type UserJWT

type UserJWT struct {
	UserID     string       `json:"user_id"`
	Email      *EmailJWT    `json:"email,omitempty"`
	Username   string       `json:"username"`
	Metadata   *MetadataJWT `json:"metadata,omitempty"`
	Name       string       `json:"name"`
	FamilyName string       `json:"family_name"`
	GivenName  string       `json:"given_name"`
	Picture    string       `json:"picture"`
	// contains filtered or unexported fields
}

UserJWT represents an abstracted user model for session management

func UserJWTFromUserModel

func UserJWTFromUserModel(userModel *models.User) UserJWT

func (*UserJWT) CustomClaims added in v3.1.0

func (u *UserJWT) CustomClaims(path ...string) interface{}

CustomClaims returns this user's tenant-declared custom claims: the whole object with no argument, or one named claim's value with a single argument - mirroring the calling convention of Metadata's Public/Unsafe accessors (path is a gjson path, joined with "."). Returns "" for a claim that doesn't exist, or for a user with no custom claims at all.

Returns interface{}, not string, so the value's real JSON type (float64/bool/string/ []interface{}/map[string]interface{}) survives when Go's text/template evaluates it as part of a larger expression - e.g. `{{if .User.CustomClaims "is_staff"}}`: Go's `if`/`and`/`or`/ `not`/`eq` all inspect the actual reflected value a subexpression produces, which is determined by this method's return type, not by how the template's FINAL output gets rendered to text. A `string`-typed return would make a `false`-valued boolean claim print as the non-empty text "false", which `if` treats as truthy - silently backwards.

This alone does NOT fix a bare `{{ .User.CustomClaims "age" }}` claim template's own output type, though: Execute always stringifies whatever the template as a whole renders to, regardless of any one method's return type. That's handled separately, by session.parseClaimTemplateValue's bare-accessor fast path, which bypasses Execute entirely for that one case and calls this same method directly.

func (*UserJWT) MarshalJSON added in v3.1.0

func (u *UserJWT) MarshalJSON() ([]byte, error)

MarshalJSON includes customClaims (unexported, so not covered by the default struct marshaling) under the same "custom_claims" key it used to occupy as a field.

func (*UserJWT) String

func (u *UserJWT) String() string

func (UserJWT) WithCustomClaims added in v3.1.0

func (u UserJWT) WithCustomClaims(claims json.RawMessage) UserJWT

WithCustomClaims returns a copy of u with its custom claims set to the given flat {claimName: value} JSON. Exported setter for the otherwise-private customClaims field, for tests in other packages (e.g. session/template_test.go) that construct a UserJWT directly - UserJWTFromUserModel (below, same package) sets the field directly instead.

type Username

type Username struct {
	ID        uuid.UUID `json:"id"`
	Username  string    `json:"username"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func FromUsernameModel

func FromUsernameModel(u *models.Username) *Username

type ValidateSessionOrganization added in v3.1.0

type ValidateSessionOrganization struct {
	ID    uuid.UUID `json:"id"`
	Name  string    `json:"name"`
	Roles []string  `json:"roles"`
}

type ValidateSessionRequest

type ValidateSessionRequest struct {
	SessionToken string `json:"session_token" validate:"required"`
}

type ValidateSessionResponse

type ValidateSessionResponse struct {
	IsValid bool    `json:"is_valid"`
	Claims  *Claims `json:"claims,omitempty"`
	// deprecated
	ExpirationTime *time.Time `json:"expiration_time,omitempty"`
	// deprecated
	UserID *uuid.UUID `json:"user_id,omitempty"`
	// IdleExpiresAt indicates when the session will expire due to inactivity, assuming no further activity occurs before this time
	IdleExpiresAt *time.Time `json:"idle_expires_at,omitempty"`
	// Organizations is computed fresh from the database on every call, not
	// embedded in or read from the JWT claims, so a role or membership
	// change takes effect immediately rather than only after the session
	// token is reissued. Omitted if the user belongs to no organizations.
	Organizations []ValidateSessionOrganization `json:"organizations,omitempty"`
}

type ValidationErrors

type ValidationErrors struct {
	Errors []string `json:"errors"`
}

type WebauthnCredentialResponse

type WebauthnCredentialResponse struct {
	ID              string     `json:"id"`
	Name            *string    `json:"name,omitempty"`
	PublicKey       string     `json:"public_key"`
	AttestationType string     `json:"attestation_type"`
	AAGUID          uuid.UUID  `json:"aaguid"`
	LastUsedAt      *time.Time `json:"last_used_at,omitempty"`
	CreatedAt       time.Time  `json:"created_at"`
	Transports      []string   `json:"transports"`
	BackupEligible  bool       `json:"backup_eligible"`
	BackupState     bool       `json:"backup_state"`
	MFAOnly         bool       `json:"mfa_only"`
}

func FromWebauthnCredentialModel

func FromWebauthnCredentialModel(c *models.WebauthnCredential) *WebauthnCredentialResponse

FromWebauthnCredentialModel Converts the DB model to a DTO object

type WebauthnCredentialUpdateRequest

type WebauthnCredentialUpdateRequest struct {
	Name *string `json:"name"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址