consoleauth

package
v1.117.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: AGPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAPIKey added in v1.14.2

func GetAPIKey(ctx context.Context) ([]byte, bool)

GetAPIKey returns api key from context is exists.

func WithAPIKey added in v1.14.2

func WithAPIKey(ctx context.Context, key []byte) context.Context

WithAPIKey creates context with api key.

Types

type Claims

type Claims struct {
	ID         uuid.UUID `json:"id"`
	Email      string    `json:"email,omitempty"`
	Expiration time.Time `json:"expires,omitempty"`
}

Claims represents data signed by server and used for authentication.

func FromJSON

func FromJSON(data []byte) (*Claims, error)

FromJSON returns Claims instance, parsed from JSON.

func (*Claims) JSON

func (c *Claims) JSON() ([]byte, error)

JSON returns json representation of Claims.

type Config added in v1.56.1

type Config struct {
	TokenExpirationTime time.Duration `help:"expiration time for account recovery and activation tokens" default:"30m"`
}

Config contains configuration parameters for console auth.

type Hmac

type Hmac struct {
	Secret []byte
}

Hmac is hmac256 based Signer.

func (*Hmac) Sign

func (a *Hmac) Sign(data []byte) ([]byte, error)

Sign implements satellite signer.

type OrderDirection added in v1.111.4

type OrderDirection uint8

OrderDirection is used for members in specific order direction.

const (
	// Ascending indicates that we should order ascending.
	Ascending OrderDirection = 1
	// Descending indicates that we should order descending.
	Descending OrderDirection = 2
)

type Service added in v1.56.1

type Service struct {
	Signer
	// contains filtered or unexported fields
}

Service handles creating, signing, and checking the expiration of auth tokens.

func NewService added in v1.56.1

func NewService(config Config, signer Signer) *Service

NewService creates a new consoleauth service.

func (*Service) CreateToken added in v1.56.1

func (s *Service) CreateToken(ctx context.Context, id uuid.UUID, email string) (_ string, err error)

CreateToken creates a new auth token.

func (*Service) IsExpired added in v1.56.1

func (s *Service) IsExpired(now, tokenCreatedAt time.Time) bool

IsExpired returns whether token is expired.

func (*Service) SignToken added in v1.56.1

func (s *Service) SignToken(token Token) ([]byte, error)

SignToken returns token signature.

func (*Service) ValidateToken added in v1.58.1

func (s *Service) ValidateToken(token Token) (bool, error)

ValidateToken determines token validity using its signature.

type Signer added in v1.56.1

type Signer interface {
	Sign(data []byte) ([]byte, error)
}

Signer creates signature for provided data.

type Token

type Token struct {
	Payload   []byte
	Signature []byte
}

Token represents authentication data structure.

func FromBase64URLString

func FromBase64URLString(token string) (Token, error)

FromBase64URLString creates Token instance from base64URLEncoded string representation.

func (Token) String

func (t Token) String() string

String returns base64URLEncoded data joined with .

type WebappSession added in v1.56.1

type WebappSession struct {
	ID                        uuid.UUID `json:"id"`
	UserID                    uuid.UUID `json:"-"`
	Address                   string    `json:"-"`
	UserAgent                 string    `json:"userAgent"`
	Status                    int       `json:"-"`
	ExpiresAt                 time.Time `json:"expiresAt"`
	IsRequesterCurrentSession bool      `json:"isRequesterCurrentSession"`
}

WebappSession represents a session on the satellite web app.

type WebappSessions added in v1.56.1

type WebappSessions interface {
	// Create creates a webapp session and returns the session info.
	Create(ctx context.Context, id, userID uuid.UUID, ip, userAgent string, expires time.Time) (WebappSession, error)
	// GetBySessionID gets the session info from the session ID.
	GetBySessionID(ctx context.Context, sessionID uuid.UUID) (WebappSession, error)
	// GetAllByUserID gets all webapp sessions with userID.
	GetAllByUserID(ctx context.Context, userID uuid.UUID) ([]WebappSession, error)
	// GetPagedActiveByUserID gets all active webapp sessions by userID, offset and limit.
	GetPagedActiveByUserID(ctx context.Context, userID uuid.UUID, expiresAt time.Time, cursor WebappSessionsCursor) (*WebappSessionsPage, error)
	// DeleteBySessionID deletes a webapp session by ID.
	DeleteBySessionID(ctx context.Context, sessionID uuid.UUID) error
	// DeleteAllByUserID deletes all webapp sessions by user ID.
	DeleteAllByUserID(ctx context.Context, userID uuid.UUID) (int64, error)
	// DeleteAllByUserIDExcept deletes all webapp sessions by user ID except one of sessionID.
	DeleteAllByUserIDExcept(ctx context.Context, userID uuid.UUID, sessionID uuid.UUID) (int64, error)
	// UpdateExpiration updates the expiration time of the session.
	UpdateExpiration(ctx context.Context, sessionID uuid.UUID, expiresAt time.Time) error
	// DeleteExpired deletes all sessions that have expired before the provided timestamp.
	DeleteExpired(ctx context.Context, now time.Time, asOfSystemTimeInterval time.Duration, pageSize int) error
}

WebappSessions is the repository for webapp sessions.

type WebappSessionsCursor added in v1.111.4

type WebappSessionsCursor struct {
	Limit          uint
	Page           uint
	Order          WebappSessionsOrder
	OrderDirection OrderDirection
}

WebappSessionsCursor holds info for webapp sessions cursor pagination.

type WebappSessionsOrder added in v1.111.4

type WebappSessionsOrder int8

WebappSessionsOrder is used for querying webapp sessions in specified order.

const (
	// UserAgent indicates that we should order by user agent.
	UserAgent WebappSessionsOrder = 1
	// ExpiresAt indicates that we should order by expiration date.
	ExpiresAt WebappSessionsOrder = 2
)

type WebappSessionsPage added in v1.111.4

type WebappSessionsPage struct {
	Sessions []WebappSession `json:"sessions"`

	Limit          uint                `json:"limit"`
	Order          WebappSessionsOrder `json:"order"`
	OrderDirection OrderDirection      `json:"orderDirection"`
	Offset         uint64              `json:"offset"`
	PageCount      uint                `json:"pageCount"`
	CurrentPage    uint                `json:"currentPage"`
	TotalCount     uint64              `json:"totalCount"`
}

WebappSessionsPage represents a page of webapp sessions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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