auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0, MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth is Skiff's accounts + teams layer: users belong to teams, and projects/env/deploys are scoped to a team. Backed by SQLite.

Index

Constants

View Source
const (
	RoleOwner  = "owner"
	RoleMember = "member"
)

Variables

View Source
var ErrBadCode = errors.New("that code didn't match — try the newest one from your app")

Functions

func CodeAt added in v0.5.0

func CodeAt(secret string, t time.Time) string

CodeAt is the authenticator code for a secret at a moment.

func NewTOTPSecret added in v0.5.0

func NewTOTPSecret() string

NewTOTPSecret makes a 160-bit secret, base32 as authenticator apps expect.

func TOTPURI added in v0.5.0

func TOTPURI(issuer, account, secret string) string

TOTPURI is what the enrolment QR code holds.

Types

type Invite

type Invite struct {
	Token   string `json:"token"`
	Email   string `json:"email"`
	TeamID  string `json:"teamId"`
	Role    string `json:"role"`
	Created int64  `json:"created"`
}

type Member

type Member struct {
	User User   `json:"user"`
	Role string `json:"role"`
}

type Store

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

func NewStore

func NewStore(db *sql.DB) *Store

func (*Store) AcceptInvite

func (s *Store) AcceptInvite(token, userID string) (Team, error)

func (*Store) Authenticate

func (s *Store) Authenticate(email, password string) (User, bool)

func (*Store) BeginTwoFactor added in v0.5.0

func (s *Store) BeginTwoFactor(userID string) (string, error)

BeginTwoFactor stores a fresh secret that only takes effect once a code from it is confirmed.

func (*Store) ChangePassword

func (s *Store) ChangePassword(userID, current, next string) error

func (*Store) CheckSecondFactor added in v0.5.0

func (s *Store) CheckSecondFactor(userID, code string) bool

CheckSecondFactor accepts a current authenticator code, each at most once, or an unused recovery code, which is then spent.

func (*Store) CreateInvite

func (s *Store) CreateInvite(email, teamID, role string) (Invite, error)

func (*Store) CreateTeam

func (s *Store) CreateTeam(name, ownerID string) (Team, error)

func (*Store) CreateUser

func (s *Store) CreateUser(email, name, password string) (User, Team, error)

func (*Store) CreateUserNoTeam

func (s *Store) CreateUserNoTeam(email, name, password string) (User, error)

CreateUserNoTeam adds a user without a personal team, for the invite flow where they join the inviter's team instead.

func (*Store) DeleteTeam

func (s *Store) DeleteTeam(teamID string) error

DeleteTeam removes a team with its memberships and invites; callers must first ensure it owns no apps or databases.

func (*Store) DeleteUser

func (s *Store) DeleteUser(userID string) error

DeleteUser removes a user and their memberships; callers must first deal with any teams the user solely owns.

func (*Store) DisableTwoFactor added in v0.5.0

func (s *Store) DisableTwoFactor(userID string) error

DisableTwoFactor turns the second step off and drops the recovery codes.

func (*Store) EnableTwoFactor added in v0.5.0

func (s *Store) EnableTwoFactor(userID, code string) ([]string, error)

EnableTwoFactor confirms the pending secret with a code from it and returns new recovery codes.

func (*Store) HasTwoFactor added in v0.5.0

func (s *Store) HasTwoFactor(userID string) bool

HasTwoFactor reports whether signing in also needs a code.

func (*Store) HasUsers

func (s *Store) HasUsers() bool

func (*Store) Invite

func (s *Store) Invite(token string) (Invite, bool)

func (*Store) LeaveTeam

func (s *Store) LeaveTeam(userID, teamID string) error

LeaveTeam drops the caller's own membership, refusing if they're the last owner.

func (*Store) Members

func (s *Store) Members(teamID string) []Member

func (*Store) RecoveryLeft added in v0.5.0

func (s *Store) RecoveryLeft(userID string) int

RecoveryLeft counts the unused recovery codes.

func (*Store) RegenerateRecovery added in v0.5.0

func (s *Store) RegenerateRecovery(userID string) ([]string, error)

RegenerateRecovery replaces every recovery code.

func (*Store) RemoveMember

func (s *Store) RemoveMember(teamID, userID string) error

RemoveMember drops a user from a team, refusing to remove the last owner.

func (*Store) RenameTeam

func (s *Store) RenameTeam(teamID, name string) error

func (*Store) Role

func (s *Store) Role(userID, teamID string) (string, bool)

func (*Store) TeamsForUser

func (s *Store) TeamsForUser(userID string) []Team

func (*Store) UpdateName

func (s *Store) UpdateName(userID, name string) error

func (*Store) User

func (s *Store) User(userID string) (User, bool)

func (*Store) UserByEmail

func (s *Store) UserByEmail(email string) (User, bool)

type Team

type Team struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Slug    string `json:"slug"`
	Created int64  `json:"created"`
}

type User

type User struct {
	ID           string `json:"id"`
	Email        string `json:"email"`
	Name         string `json:"name"`
	PasswordHash string `json:"passwordHash,omitempty"`
	Created      int64  `json:"created"`
}

Jump to

Keyboard shortcuts

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