Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package store is the database of accounts and sign-in (schema auth): the schema (migrations), the queries (sqlc) and the migration runner.

After editing migrations/ or queries.sql:

go tool -modfile=tools/go.mod sqlc generate -f server/auth/store/sqlc.yaml

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate brings the database schema to the latest version.

Types

type AddEventParams

type AddEventParams struct {
	UserID    string
	SessionID *string
	Kind      string
	Ip        string
	Detail    string
	CreatedAt time.Time
}

type ApproveDeviceCodeParams

type ApproveDeviceCodeParams struct {
	UserCode   string
	UserID     *string
	ApprovedAt *time.Time
}

type AuthorizationCode

type AuthorizationCode struct {
	CodeHash      []byte
	UserID        string
	CodeChallenge string
	RedirectUri   string
	CreatedAt     time.Time
	ExpiresAt     time.Time
	UsedAt        *time.Time
}

type ConsumeChallengeParams

type ConsumeChallengeParams struct {
	ID         string
	ConsumedAt *time.Time
}

type ConsumeDeviceCodeParams

type ConsumeDeviceCodeParams struct {
	DeviceCodeHash []byte
	ConsumedAt     *time.Time
}

type CountChallengesByDeviceParams

type CountChallengesByDeviceParams struct {
	DeviceID  string
	CreatedAt time.Time
}

type CountChallengesByEmailParams

type CountChallengesByEmailParams struct {
	Email     string
	CreatedAt time.Time
}

type CountChallengesByIPParams

type CountChallengesByIPParams struct {
	Ip        string
	CreatedAt time.Time
}

type CreateAuthorizationCodeParams

type CreateAuthorizationCodeParams struct {
	CodeHash      []byte
	UserID        string
	CodeChallenge string
	RedirectUri   string
	CreatedAt     time.Time
	ExpiresAt     time.Time
}

type CreateChallengeParams

type CreateChallengeParams struct {
	ID        string
	Email     string
	Purpose   string
	CodeHash  []byte
	Ip        string
	DeviceID  string
	CreatedAt time.Time
	ExpiresAt time.Time
}

type CreateDeviceCodeParams

type CreateDeviceCodeParams struct {
	DeviceCodeHash []byte
	UserCode       string
	DeviceName     string
	Ip             string
	CreatedAt      time.Time
	ExpiresAt      time.Time
}

type CreateRefreshTokenParams

type CreateRefreshTokenParams struct {
	TokenHash []byte
	SessionID string
	CreatedAt time.Time
}

type CreateSessionParams

type CreateSessionParams struct {
	ID            string
	UserID        string
	DeviceName    string
	Ip            string
	CreatedAt     time.Time
	IdleExpiresAt time.Time
	ExpiresAt     time.Time
}

type CreateSigningKeyParams

type CreateSigningKeyParams struct {
	ID         string
	PrivateKey []byte
	CreatedAt  time.Time
}

type CreateUserParams

type CreateUserParams struct {
	ID        string
	Email     string
	CreatedAt time.Time
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type DeviceCode

type DeviceCode struct {
	DeviceCodeHash []byte
	UserCode       string
	DeviceName     string
	Ip             string
	CreatedAt      time.Time
	ExpiresAt      time.Time
	LastPolledAt   *time.Time
	UserID         *string
	ApprovedAt     *time.Time
	ConsumedAt     *time.Time
}

type EmailChallenge

type EmailChallenge struct {
	ID         string
	Email      string
	Purpose    string
	CodeHash   []byte
	Attempts   int32
	Ip         string
	DeviceID   string
	CreatedAt  time.Time
	ExpiresAt  time.Time
	ConsumedAt *time.Time
}

type LiveSessionsParams

type LiveSessionsParams struct {
	UserID        string
	IdleExpiresAt time.Time
}

type PollDeviceCodeParams

type PollDeviceCodeParams struct {
	DeviceCodeHash []byte
	LastPolledAt   *time.Time
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) AddChallengeAttempt

func (q *Queries) AddChallengeAttempt(ctx context.Context, id string) error

func (*Queries) AddEvent

func (q *Queries) AddEvent(ctx context.Context, arg AddEventParams) error

func (*Queries) ApproveDeviceCode

func (q *Queries) ApproveDeviceCode(ctx context.Context, arg ApproveDeviceCodeParams) (int64, error)

func (*Queries) AuthorizationCodeForUpdate

func (q *Queries) AuthorizationCodeForUpdate(ctx context.Context, codeHash []byte) (AuthorizationCode, error)

func (*Queries) ChallengeForUpdate

func (q *Queries) ChallengeForUpdate(ctx context.Context, id string) (EmailChallenge, error)

func (*Queries) ConsumeChallenge

func (q *Queries) ConsumeChallenge(ctx context.Context, arg ConsumeChallengeParams) error

func (*Queries) ConsumeDeviceCode

func (q *Queries) ConsumeDeviceCode(ctx context.Context, arg ConsumeDeviceCodeParams) error

func (*Queries) CountChallengesByDevice

func (q *Queries) CountChallengesByDevice(ctx context.Context, arg CountChallengesByDeviceParams) (int64, error)

func (*Queries) CountChallengesByEmail

func (q *Queries) CountChallengesByEmail(ctx context.Context, arg CountChallengesByEmailParams) (int64, error)

func (*Queries) CountChallengesByIP

func (q *Queries) CountChallengesByIP(ctx context.Context, arg CountChallengesByIPParams) (int64, error)

func (*Queries) CreateAuthorizationCode

func (q *Queries) CreateAuthorizationCode(ctx context.Context, arg CreateAuthorizationCodeParams) error

func (*Queries) CreateChallenge

func (q *Queries) CreateChallenge(ctx context.Context, arg CreateChallengeParams) error

func (*Queries) CreateDeviceCode

func (q *Queries) CreateDeviceCode(ctx context.Context, arg CreateDeviceCodeParams) error

func (*Queries) CreateRefreshToken

func (q *Queries) CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) error

func (*Queries) CreateSession

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)

func (*Queries) CreateSigningKey

func (q *Queries) CreateSigningKey(ctx context.Context, arg CreateSigningKeyParams) error

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)

func (*Queries) DeleteExpired

func (q *Queries) DeleteExpired(ctx context.Context, expiresAt time.Time) error

func (*Queries) DeviceCodeByUserCode

func (q *Queries) DeviceCodeByUserCode(ctx context.Context, userCode string) (DeviceCode, error)

func (*Queries) DeviceCodeForUpdate

func (q *Queries) DeviceCodeForUpdate(ctx context.Context, deviceCodeHash []byte) (DeviceCode, error)

func (*Queries) LiveSessions

func (q *Queries) LiveSessions(ctx context.Context, arg LiveSessionsParams) ([]Session, error)

func (*Queries) PollDeviceCode

func (q *Queries) PollDeviceCode(ctx context.Context, arg PollDeviceCodeParams) error

func (*Queries) RefreshTokenForUpdate

func (q *Queries) RefreshTokenForUpdate(ctx context.Context, tokenHash []byte) (RefreshToken, error)

func (*Queries) RevokeSession

func (q *Queries) RevokeSession(ctx context.Context, arg RevokeSessionParams) error

func (*Queries) SessionByID

func (q *Queries) SessionByID(ctx context.Context, id string) (Session, error)

func (*Queries) SessionForUpdate

func (q *Queries) SessionForUpdate(ctx context.Context, id string) (Session, error)

func (*Queries) SigningKeys

func (q *Queries) SigningKeys(ctx context.Context) ([]SigningKey, error)

func (*Queries) TouchSession

func (q *Queries) TouchSession(ctx context.Context, arg TouchSessionParams) (Session, error)

func (*Queries) UseAuthorizationCode

func (q *Queries) UseAuthorizationCode(ctx context.Context, arg UseAuthorizationCodeParams) error

func (*Queries) UseRefreshToken

func (q *Queries) UseRefreshToken(ctx context.Context, arg UseRefreshTokenParams) error

func (*Queries) UserByEmail

func (q *Queries) UserByEmail(ctx context.Context, email string) (User, error)

func (*Queries) UserByID

func (q *Queries) UserByID(ctx context.Context, id string) (User, error)

func (*Queries) UserEvents

func (q *Queries) UserEvents(ctx context.Context, userID string) ([]SecurityEvent, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type RefreshToken

type RefreshToken struct {
	TokenHash []byte
	SessionID string
	CreatedAt time.Time
	UsedAt    *time.Time
}

type RevokeSessionParams

type RevokeSessionParams struct {
	ID           string
	RevokedAt    *time.Time
	RevokeReason *string
}

type SecurityEvent

type SecurityEvent struct {
	ID        int64
	UserID    string
	SessionID *string
	Kind      string
	Ip        string
	Detail    string
	CreatedAt time.Time
}

type Session

type Session struct {
	ID            string
	UserID        string
	DeviceName    string
	Ip            string
	CreatedAt     time.Time
	LastUsedAt    time.Time
	IdleExpiresAt time.Time
	ExpiresAt     time.Time
	RevokedAt     *time.Time
	RevokeReason  *string
}

type SigningKey

type SigningKey struct {
	ID         string
	PrivateKey []byte
	CreatedAt  time.Time
}

type TouchSessionParams

type TouchSessionParams struct {
	ID            string
	LastUsedAt    time.Time
	IdleExpiresAt time.Time
}

type UseAuthorizationCodeParams

type UseAuthorizationCodeParams struct {
	CodeHash []byte
	UsedAt   *time.Time
}

type UseRefreshTokenParams

type UseRefreshTokenParams struct {
	TokenHash []byte
	UsedAt    *time.Time
}

type User

type User struct {
	ID        string
	Email     string
	CreatedAt time.Time
}

Jump to

Keyboard shortcuts

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