auth

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin interface {
	EnsureSetup(ctx context.Context) error
	GetOrCreateClient(ctx context.Context, clientID string) (Client, error)

	CreateUser(ctx context.Context, username, password string) error
	DeleteUser(ctx context.Context, username string) error
	GetUser(ctx context.Context, username string) (User, error)
	GetUsers(ctx context.Context) (map[string]User, error)
	UpdateUser(ctx context.Context, user User) error
}

func NewAdmin

func NewAdmin(core Core, opts ...AdminOption) Admin

type AdminOption

type AdminOption func(*adminConfig)

func ClientID

func ClientID(clientID string) AdminOption

func MasterRealm added in v0.1.6

func MasterRealm(masterRealm string) AdminOption

func Password

func Password(password string) AdminOption

func Realm

func Realm(realm string) AdminOption

func Username

func Username(username string) AdminOption

type Client

type Client interface {
	GetID() string
	GetSecret() string
	CreateSession(ctx context.Context) (Session, error)
	CreateUserSession(ctx context.Context, username, password string) (Session, error)
}

func NewClient

func NewClient(core Core, id, secret, realm string) Client

type Core

type Core interface {
	GetClient() *gocloak.GoCloak
}

func NewCore

func NewCore(opts ...CoreOption) Core

type CoreOption

type CoreOption func(*coreConfig)

func BaseURL

func BaseURL(url string) CoreOption

type Event

type Event interface {
	Time() time.Time
	Type() EventType
	RealmID() string
	ClientID() string
	UserID() string
	SessionID() string
	IPAddress() string
	Error() string
	Details() map[string]string
}

type EventEmitter

type EventEmitter interface {
	Signal() signalslots.Signal
	ProcessNextBatch(ctx context.Context, session Session) error
}

func NewEventEmitter

func NewEventEmitter(core Core, opts ...EventEmitterOption) EventEmitter

type EventEmitterOption

type EventEmitterOption func(*eventEmitterConfig)

func BatchSize

func BatchSize(size int) EventEmitterOption

func EventTypes

func EventTypes(types ...EventType) EventEmitterOption

type EventType

type EventType string
const (
	// Login Events
	EventLogin       EventType = "LOGIN"
	EventLoginError  EventType = "LOGIN_ERROR"
	EventLogout      EventType = "LOGOUT"
	EventLogoutError EventType = "LOGOUT_ERROR"

	// Registration Events
	EventRegister      EventType = "REGISTER"
	EventRegisterError EventType = "REGISTER_ERROR"
	EventDeleteAccount EventType = "DELETE_ACCOUNT"
	EventDeleteError   EventType = "DELETE_ACCOUNT_ERROR"

	// User Profile Events
	EventUpdateProfile  EventType = "UPDATE_PROFILE"
	EventUpdatePassword EventType = "UPDATE_PASSWORD"
	EventUpdateEmail    EventType = "UPDATE_EMAIL"
	EventVerifyEmail    EventType = "VERIFY_EMAIL"
	EventUpdateLocale   EventType = "UPDATE_LOCALE"

	// Identity Provider Events
	EventLinkIDP       EventType = "IDENTITY_PROVIDER_LINK"
	EventUnlinkIDP     EventType = "IDENTITY_PROVIDER_UNLINK"
	EventLoginIDP      EventType = "IDENTITY_PROVIDER_LOGIN"
	EventFirstLoginIDP EventType = "IDENTITY_PROVIDER_FIRST_LOGIN"
	EventPostLoginIDP  EventType = "IDENTITY_PROVIDER_POST_LOGIN"
	EventResponseIDP   EventType = "IDENTITY_PROVIDER_RESPONSE"

	// 2FA/MFA Events
	EventRemoveTotp     EventType = "REMOVE_TOTP"
	EventUpdateTotp     EventType = "UPDATE_TOTP"
	EventGrantConsent   EventType = "GRANT_CONSENT"
	EventUpdateConsent  EventType = "UPDATE_CONSENT"
	EventRevokeConsent  EventType = "REVOKE_CONSENT"
	EventCodeToToken    EventType = "CODE_TO_TOKEN"
	EventCustomRequired EventType = "CUSTOM_REQUIRED_ACTION"

	// Client Events
	EventClientLogin     EventType = "CLIENT_LOGIN"
	EventClientLogout    EventType = "CLIENT_LOGOUT"
	EventClientRegister  EventType = "CLIENT_REGISTER"
	EventClientDelete    EventType = "CLIENT_DELETE"
	EventClientUpdate    EventType = "CLIENT_UPDATE"
	EventClientInfo      EventType = "CLIENT_INFO"
	EventClientInitLogin EventType = "CLIENT_INITIATED_ACCOUNT_LINKING"

	// Token Events
	EventTokenRefresh    EventType = "REFRESH_TOKEN"
	EventTokenExchange   EventType = "TOKEN_EXCHANGE"
	EventIntrospectToken EventType = "INTROSPECT_TOKEN"
	EventValidateToken   EventType = "VALIDATE_ACCESS_TOKEN"

	// Role Events
	EventGrantRole  EventType = "GRANT_ROLE"
	EventRemoveRole EventType = "REMOVE_ROLE"
	EventUpdateRole EventType = "UPDATE_ROLE"

	// Permission Events
	EventPermissionGrant  EventType = "PERMISSION_GRANT"
	EventPermissionRevoke EventType = "PERMISSION_REVOKE"

	// Group Events
	EventGroupMembership EventType = "GROUP_MEMBERSHIP"
	EventJoinGroup       EventType = "JOIN_GROUP"
	EventLeaveGroup      EventType = "LEAVE_GROUP"

	// Session Events
	EventRestart              EventType = "RESTART_AUTHENTICATION"
	EventImpersonate          EventType = "IMPERSONATE"
	EventBackchannelLogin     EventType = "BACKCHANNEL_LOGIN"
	EventBackchannelLogout    EventType = "BACKCHANNEL_LOGOUT"
	EventClientSessionExpired EventType = "CLIENT_SESSION_EXPIRED"
	EventSessionExpired       EventType = "SESSION_EXPIRED"
)

type Session

type Session interface {
	Refresh(context.Context) error
	Revoke(context.Context) error

	PastHalfLife(context.Context) bool
	GetOwnerName(context.Context) (string, error)
	IsValid(context.Context) bool

	AccessToken() string
	RefreshToken() string
	Realm() string
	ClientID() string
	ClientSecret() string
}

func NewSession

func NewSession(core Core, token *gocloak.JWT, clientID, clientSecret, realm string) Session

type User

type User interface {
	GetID() string
	GetUsername() string
	GetFirstName() string
	GetLastName() string
	GetEmail() string
	IsEmailVerified() bool
	IsEnabled() bool
	GetRoles() []string

	SetUsername(username string)
	SetFirstName(firstName string)
	SetLastName(lastName string)
	SetEmail(email string)
	SetEmailVerified(emailVerified bool)
	SetEnabled(enabled bool)
	SetRoles(roles []string)
}

func NewUser

func NewUser() User

Jump to

Keyboard shortcuts

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