authentication

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithUser

func ContextWithUser[U any](ctx context.Context, u *U) context.Context

ContextWithUser returns a new context carrying the service's user entity. The auth middleware sets it after authentication; handlers read it with UserFromContext.

func UserFromContext

func UserFromContext[U any](ctx context.Context) *U

UserFromContext returns the service's user entity from the context, or nil if none is present (e.g. service-account requests, or unauthenticated ones).

Types

type Authenticator

type Authenticator[U any] interface {
	Authenticate(ctx context.Context, token string) (*authorization.Actor, *U, error)
	EnsureRoles(ctx context.Context, token string, actor *authorization.Actor) (*authorization.Actor, error)
}

Authenticator validates a bearer token and returns the resolved actor and the service's user entity. The user is nil for service-account actors.

EnsureRoles completes the actor's realm roles for routes that need them (admin routes), fetching from the identity provider only when the token omitted roles. It is a no-op when roles are already present or when the driver embeds them in the credential, so it is safe to call on any actor.

type UserInfo

type UserInfo struct {
	ID          string  `json:"id"`
	Email       string  `json:"email"`
	PhoneNumber *string `json:"phone_number"`
	Username    string  `json:"username"`
	FirstName   *string `json:"first_name"`
	LastName    *string `json:"last_name"`
	CountryISO  string  `json:"country_iso"`
	Locale      string  `json:"locale"`
}

UserInfo holds the basic user information used by authentication services.

type UserResolver

type UserResolver[U any] interface {
	Handle(ctx context.Context, info UserInfo) (*U, error)
}

UserResolver loads or creates user with given user info from token and returning a user instance. The generic type U represents the user model that will be resolved.

Jump to

Keyboard shortcuts

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