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

auth

package
v0.2.50 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOIDCProbe         = errors.New("OIDC issuer could not be verified")
	ErrOIDCActivation    = errors.New("organisation OIDC requires current issuer verification before activation")
	ErrOIDCUnavailable   = errors.New("OIDC secret storage unavailable")
	ErrOIDCProbeCooldown = errors.New("OIDC issuer probe cooldown active")
	ErrOIDCProbeBusy     = errors.New("OIDC issuer probe capacity reached")
)
View Source
var (
	ErrUnauthenticated = errors.New("authentication required")
	ErrForbidden       = errors.New("access denied")
	ErrConflict        = errors.New("version conflict")
	ErrInvalid         = errors.New("invalid request")
)
View Source
var ErrInvitationAccepted = fmt.Errorf("invitation already accepted: %w", ErrConflict)
View Source
var ErrSlugTaken = fmt.Errorf("short name already in use: %w", ErrConflict)

Functions

func CanReadRepository

func CanReadRepository(actor domain.Actor, repositoryID string) bool

func CreatePlatformInvitation added in v0.2.11

func CreatePlatformInvitation(ctx context.Context, db *store.Store, orgName, email, rawSlug string) (string, error)

func NormaliseSlug added in v0.2.19

func NormaliseSlug(raw string) (string, bool)

func RevokePlatformInvitation added in v0.2.14

func RevokePlatformInvitation(ctx context.Context, db *store.Store, id string) error

func ValidID

func ValidID(id string) bool

Types

type Config

type Config struct {
	PublicURL          string
	Edition            string
	Development        bool
	FixtureAuth        bool
	ListenAddress      string
	OIDCIssuer         string
	OIDCClientID       string
	OIDCClientSecret   string `json:"-"`
	BootstrapToken     string `json:"-"`
	BootstrapExpiresAt time.Time
}

func (Config) LogValue

func (c Config) LogValue() slog.Value

func (Config) String

func (c Config) String() string

type CreatedOrgOIDCInvitation

type CreatedOrgOIDCInvitation struct {
	OrgOIDCInvitation
	RedemptionURL string `json:"redemption_url"`
}

type Membership

type Membership struct {
	OrgID           string      `json:"org_id"`
	UserID          string      `json:"user_id,omitempty"`
	Role            domain.Role `json:"role"`
	TeamIDs         []string    `json:"team_ids"`
	RepositoryIDs   []string    `json:"repository_ids"`
	AllRepositories bool        `json:"all_repositories"`
	Version         int64       `json:"version"`
}

type OrgOIDCInput

type OrgOIDCInput struct {
	Issuer       string `json:"issuer"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type OrgOIDCInvitation

type OrgOIDCInvitation struct {
	ID        string      `json:"id"`
	Email     string      `json:"email"`
	Role      domain.Role `json:"role"`
	ExpiresAt time.Time   `json:"expires_at"`
	CreatedAt time.Time   `json:"created_at"`
	Redeemed  bool        `json:"redeemed"`
}

type OrgOIDCInvitationInput

type OrgOIDCInvitationInput struct {
	Email     string      `json:"email"`
	Role      domain.Role `json:"role"`
	ExpiresAt time.Time   `json:"expires_at"`
}

type OrgOIDCSettings

type OrgOIDCSettings struct {
	Configured          bool       `json:"configured"`
	SecretPresent       bool       `json:"secret_present"`
	Issuer              string     `json:"issuer,omitempty"`
	ClientID            string     `json:"client_id,omitempty"`
	Status              string     `json:"status"`
	Version             int64      `json:"version"`
	VerifiedAt          *time.Time `json:"verified_at,omitempty"`
	Verified            bool       `json:"verified"`
	ActivationAvailable bool       `json:"activation_available"`
	ActivationBlocked   string     `json:"activation_blocked,omitempty"`
}

type PendingInvitation added in v0.2.14

type PendingInvitation struct {
	ID        string      `json:"id"`
	Email     string      `json:"email"`
	OrgName   string      `json:"org_name"`
	Role      domain.Role `json:"role"`
	ExpiresAt time.Time   `json:"expires_at"`
}

func PlatformInvitations added in v0.2.14

func PlatformInvitations(ctx context.Context, db *store.Store) ([]PendingInvitation, error)

type ProbeCooldownError

type ProbeCooldownError struct {
	RetryAfter int
}

func (*ProbeCooldownError) Error

func (e *ProbeCooldownError) Error() string

func (*ProbeCooldownError) Is

func (e *ProbeCooldownError) Is(target error) bool

type RepositoryResolver

type RepositoryResolver func(context.Context, pgx.Tx, string, string) (string, error)

type Service

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

func New

func New(ctx context.Context, db *store.Store, cfg Config) (*Service, error)

func (*Service) ActivateOrgOIDC

func (s *Service) ActivateOrgOIDC(ctx context.Context, session Session, orgID string, expected int64, requestID string) error

func (*Service) ActorTx

func (s *Service) ActorTx(ctx context.Context, tx pgx.Tx, session Session, org string) (domain.Actor, error)

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, token string) (Session, error)

func (*Service) BeginOrgOIDCInvitation

func (s *Service) BeginOrgOIDCInvitation(ctx context.Context, w http.ResponseWriter, token string) (string, error)

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, session Session, token, name, requestID string) (domain.Organisation, error)

func (*Service) Callback

func (s *Service) Callback(ctx context.Context, w http.ResponseWriter, r *http.Request) error

func (*Service) CheckInvitationRequest

func (s *Service) CheckInvitationRequest(r *http.Request) error

func (*Service) CheckRequest

func (s *Service) CheckRequest(r *http.Request, csrf string) error

func (*Service) ClearJoin added in v0.2.11

func (s *Service) ClearJoin(w http.ResponseWriter)

func (*Service) ClearSession

func (s *Service) ClearSession(w http.ResponseWriter)

func (*Service) CookieName

func (s *Service) CookieName() string

func (*Service) CreateMemberInvitation added in v0.2.14

func (s *Service) CreateMemberInvitation(ctx context.Context, session Session, orgID, email string, role domain.Role, requestID string) (string, string, error)

func (*Service) CreateOrgOIDCInvitation

func (s *Service) CreateOrgOIDCInvitation(ctx context.Context, session Session, orgID string, input OrgOIDCInvitationInput, requestID string) (CreatedOrgOIDCInvitation, error)

func (*Service) DeleteMember

func (s *Service) DeleteMember(ctx context.Context, session Session, orgID, userID string, expected int64, requestID string) error

func (*Service) DeleteTeam

func (s *Service) DeleteTeam(ctx context.Context, session Session, orgID, teamID string, expected int64, requestID string) error

func (*Service) DisableOrgOIDC

func (s *Service) DisableOrgOIDC(ctx context.Context, session Session, orgID string, expected int64, requestID string) (OrgOIDCSettings, error)

func (*Service) Join added in v0.2.11

func (s *Service) Join(r *http.Request) string

func (*Service) Login

func (s *Service) Login(ctx context.Context, w http.ResponseWriter, orgIDs ...string) (string, error)

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, session Session) error

func (*Service) MemberInvitations added in v0.2.14

func (s *Service) MemberInvitations(ctx context.Context, session Session, orgID string) ([]PendingInvitation, error)

func (*Service) Members

func (s *Service) Members(ctx context.Context, session Session, orgID string, limit int, cursor string) (domain.Page[Membership], error)

func (*Service) OrgForSlug added in v0.2.19

func (s *Service) OrgForSlug(ctx context.Context, raw string) (string, error)

func (*Service) OrgOIDC

func (s *Service) OrgOIDC(ctx context.Context, session Session, orgID string) (OrgOIDCSettings, error)

func (*Service) OrgOIDCInvitations

func (s *Service) OrgOIDCInvitations(ctx context.Context, session Session, orgID string, limit int, cursor string) (domain.Page[OrgOIDCInvitation], error)

func (*Service) ProbeOrgOIDC

func (s *Service) ProbeOrgOIDC(ctx context.Context, session Session, orgID string, expected int64, requestID string) (OrgOIDCSettings, error)

func (*Service) PutMember

func (s *Service) PutMember(ctx context.Context, session Session, orgID, userID string, input Membership, expected int64, requestID string) (Membership, error)

func (*Service) PutOrgOIDC

func (s *Service) PutOrgOIDC(ctx context.Context, session Session, orgID string, input OrgOIDCInput, expected int64, requestID string) (OrgOIDCSettings, error)

func (*Service) PutTeam

func (s *Service) PutTeam(ctx context.Context, session Session, orgID, teamID string, input Team, expected int64, requestID string) (Team, error)

func (*Service) RedeemPlatformInvitation added in v0.2.11

func (s *Service) RedeemPlatformInvitation(ctx context.Context, session Session, token, requestID string) (domain.Organisation, error)

func (*Service) RequestToken

func (s *Service) RequestToken(r *http.Request) string

func (*Service) RequireRepository

func (s *Service) RequireRepository(ctx context.Context, session Session, orgID, repositoryID string) (domain.Actor, error)

func (*Service) ResolveActor

func (s *Service) ResolveActor(ctx context.Context, session Session, orgID string) (domain.Actor, error)

func (*Service) ResolveRepository

func (s *Service) ResolveRepository(ctx context.Context, session Session, orgID, objectID string, resolve RepositoryResolver) (domain.Actor, error)

func (*Service) RevokeMemberInvitation added in v0.2.14

func (s *Service) RevokeMemberInvitation(ctx context.Context, session Session, orgID, id, requestID string) error

func (*Service) RevokeOrgOIDCInvitation

func (s *Service) RevokeOrgOIDCInvitation(ctx context.Context, session Session, orgID, invitationID, requestID string) error

func (*Service) RevokeSessions

func (s *Service) RevokeSessions(ctx context.Context, session Session) error

func (*Service) SetJoin added in v0.2.11

func (s *Service) SetJoin(w http.ResponseWriter, token string)

func (*Service) SetOrgOIDCVault

func (s *Service) SetOrgOIDCVault(vault *secrets.Vault)

func (*Service) SetOrganisationSlug added in v0.2.19

func (s *Service) SetOrganisationSlug(ctx context.Context, session Session, orgID, raw, requestID string) (string, error)

func (*Service) SetSession

func (s *Service) SetSession(w http.ResponseWriter, token string)

func (*Service) SignedOutURL added in v0.2.17

func (s *Service) SignedOutURL() string

func (*Service) Teams

func (s *Service) Teams(ctx context.Context, session Session, orgID string, limit int, cursor string) (domain.Page[Team], error)

func (*Service) WithActor

func (s *Service) WithActor(ctx context.Context, session Session, orgID string, fn func(pgx.Tx, domain.Actor) error) error

func (*Service) WithMutation

func (s *Service) WithMutation(ctx context.Context, session Session, orgID string, fn func(pgx.Tx, domain.Actor) error) error

type Session

type Session struct {
	ID                string                `json:"-"`
	OrganizationID    string                `json:"-"`
	OIDCConfigID      string                `json:"-"`
	OIDCConfigVersion int64                 `json:"-"`
	User              User                  `json:"user"`
	Organisations     []domain.Organisation `json:"organisations"`
	Memberships       []Membership          `json:"memberships"`
	CSRFToken         string                `json:"csrf_token"`
	// contains filtered or unexported fields
}

func NewAutomationSession

func NewAutomationSession(org, user, grant string, repositories []string, verify func(context.Context, pgx.Tx) error) (Session, error)

func (Session) AutomationID

func (s Session) AutomationID() string

func (Session) AutomationRepositories added in v0.2.38

func (s Session) AutomationRepositories() []string

type Team

type Team struct {
	ID            string   `json:"id"`
	Name          string   `json:"name"`
	RepositoryIDs []string `json:"repository_ids"`
	Version       int64    `json:"version"`
}

type Tenant added in v0.2.14

type Tenant struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	CreatedAt    time.Time `json:"created_at"`
	Owners       []string  `json:"owners"`
	Members      int       `json:"members"`
	Repositories int       `json:"repositories"`
}

func PlatformTenants added in v0.2.14

func PlatformTenants(ctx context.Context, db *store.Store) ([]Tenant, error)

type User

type User struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

Jump to

Keyboard shortcuts

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