auth

package
v0.0.0-...-33942d2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	QuotaTargetSrv quota.TargetSrv = "auth"
	QuotaTarget    quota.Target    = "session"
)

Variables

View Source
var (
	ErrUserTokenNotFound       = errors.New("user token not found")
	ErrInvalidSessionToken     = usertoken.ErrInvalidSessionToken
	ErrExternalSessionNotFound = errors.New("external session not found")
)

Typed errors

Functions

This section is empty.

Types

type CreateTokenCommand

type CreateTokenCommand struct {
	User            *user.User
	ClientIP        net.IP
	UserAgent       string
	ExternalSession *ExternalSession
}

type CreateTokenErr

type CreateTokenErr struct {
	StatusCode  int
	InternalErr error
	ExternalErr string
}

CreateTokenErr represents a token creation error; used in Enterprise

func (*CreateTokenErr) Error

func (e *CreateTokenErr) Error() string

type ExternalSession

type ExternalSession struct {
	ID            int64     `xorm:"pk autoincr 'id'"`
	UserID        int64     `xorm:"user_id"`
	UserAuthID    int64     `xorm:"user_auth_id"`
	AuthModule    string    `xorm:"auth_module"`
	AccessToken   string    `xorm:"access_token"`
	IDToken       string    `xorm:"id_token"`
	RefreshToken  string    `xorm:"refresh_token"`
	SessionID     string    `xorm:"session_id"`
	SessionIDHash string    `xorm:"session_id_hash"`
	NameID        string    `xorm:"name_id"`
	NameIDHash    string    `xorm:"name_id_hash"`
	ExpiresAt     time.Time `xorm:"expires_at"`
	CreatedAt     time.Time `xorm:"created 'created_at'"`
}

func (*ExternalSession) Clone

func (e *ExternalSession) Clone() *ExternalSession

func (*ExternalSession) TableName

func (e *ExternalSession) TableName() string

type ExternalSessionStore

type ExternalSessionStore interface {
	// Get returns the external session
	Get(ctx context.Context, ID int64) (*ExternalSession, error)
	// List returns all external sessions fπor the given query
	List(ctx context.Context, query *ListExternalSessionQuery) ([]*ExternalSession, error)
	// Create creates a new external session for a user
	Create(ctx context.Context, extSesion *ExternalSession) error
	// Update updates an external session
	Update(ctx context.Context, ID int64, cmd *UpdateExternalSessionCommand) error
	// Delete deletes an external session
	Delete(ctx context.Context, ID int64) error
	// DeleteExternalSessionsByUserID deletes an external session
	DeleteExternalSessionsByUserID(ctx context.Context, userID int64) error
	// BatchDeleteExternalSessionsByUserIDs deletes external sessions by user IDs
	BatchDeleteExternalSessionsByUserIDs(ctx context.Context, userIDs []int64) error
}

type IDService

type IDService interface {
	// SignIdentity signs a id token for provided identity that can be forwarded to plugins and external services
	SignIdentity(ctx context.Context, id identity.Requester) (string, *authnlib.Claims[authnlib.IDTokenClaims], error)

	// RemoveIDToken removes any locally stored id tokens for key
	RemoveIDToken(ctx context.Context, identity identity.Requester) error
}

type IDSigner

type IDSigner interface {
	SignIDToken(ctx context.Context, claims *IDClaims) (string, error)
}

type JWTVerifierService

type JWTVerifierService = jwt.JWTService

type ListExternalSessionQuery

type ListExternalSessionQuery struct {
	ID        int64
	UserID    int64
	NameID    string
	SessionID string
}

type RevokeAuthTokenCmd

type RevokeAuthTokenCmd struct {
	AuthTokenId int64 `json:"authTokenId"`
}

type RotateCommand

type RotateCommand struct {
	// token is the un-hashed token
	UnHashedToken string
	IP            net.IP
	UserAgent     string
}

type TokenExpiredError

type TokenExpiredError struct {
	UserID  int64
	TokenID int64
}

func (*TokenExpiredError) Error

func (e *TokenExpiredError) Error() string

func (*TokenExpiredError) Unwrap

func (e *TokenExpiredError) Unwrap() error

type TokenRevokedError

type TokenRevokedError = usertoken.TokenRevokedError

type UpdateExternalSessionCommand

type UpdateExternalSessionCommand struct {
	Token *oauth2.Token
}

type UserToken

type UserToken = usertoken.UserToken

type UserTokenBackgroundService

type UserTokenBackgroundService interface {
	registry.BackgroundService
}

type UserTokenService

type UserTokenService interface {
	CreateToken(ctx context.Context, cmd *CreateTokenCommand) (*UserToken, error)
	LookupToken(ctx context.Context, unhashedToken string) (*UserToken, error)
	GetTokenByExternalSessionID(ctx context.Context, externalSessionID int64) (*UserToken, error)
	GetExternalSession(ctx context.Context, externalSessionID int64) (*ExternalSession, error)
	FindExternalSessions(ctx context.Context, query *ListExternalSessionQuery) ([]*ExternalSession, error)
	UpdateExternalSession(ctx context.Context, externalSessionID int64, cmd *UpdateExternalSessionCommand) error

	// RotateToken will always rotate a valid token
	RotateToken(ctx context.Context, cmd RotateCommand) (*UserToken, error)
	RevokeToken(ctx context.Context, token *UserToken, soft bool) error
	RevokeAllUserTokens(ctx context.Context, userID int64) error
	GetUserToken(ctx context.Context, userID, userTokenID int64) (*UserToken, error)
	GetUserTokens(ctx context.Context, userID int64) ([]*UserToken, error)
	ActiveTokenCount(ctx context.Context, userID *int64) (int64, error)
	GetUserRevokedTokens(ctx context.Context, userID int64) ([]*UserToken, error)
}

UserTokenService are used for generating and validating user tokens

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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