consoleauth

package
v1.79.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 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 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
	UserID    uuid.UUID
	Address   string
	UserAgent string
	Status    int
	ExpiresAt time.Time
}

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)
	// 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)
	// UpdateExpiration updates the expiration time of the session.
	UpdateExpiration(ctx context.Context, sessionID uuid.UUID, expiresAt time.Time) (err error)
}

WebappSessions is the repository for webapp sessions.

Jump to

Keyboard shortcuts

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