Documentation
¶
Overview ¶
Package pat implements personal access tokens: long-lived, named, scoped bearer credentials a user creates for themselves (a CLI, a script, an integration) outside of an interactive login. It has no notion of HTTP — a host application resolves an incoming bearer header via Resolve and decides what to do with the result.
Index ¶
- Variables
- func HasScope(t store.PersonalAccessToken, scope string) bool
- type Config
- type Service
- func (s *Service) CreateToken(ctx context.Context, userID, name string, scopes []string, ...) (string, store.PersonalAccessToken, error)
- func (s *Service) ListTokens(ctx context.Context, userID string) ([]store.PersonalAccessToken, error)
- func (s *Service) Resolve(ctx context.Context, rawToken string) (store.PersonalAccessToken, error)
- func (s *Service) RevokeToken(ctx context.Context, userID, tokenID string) error
- type Stores
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidToken = errors.New("authit/pat: invalid, revoked, or expired token") ErrExpiryTooFar = errors.New("authit/pat: requested expiry exceeds the configured maximum") ErrExpiryRequired = errors.New("authit/pat: an expiry is required") ErrNotOwner = errors.New("authit/pat: token does not belong to this user") )
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Prefix is prepended to every generated token, e.g. "ghp_" or "mb_",
// so a token is recognizable at a glance (in a shell history, a leaked
// log line, a secret scanner's rule). Defaults to "authit_".
Prefix string
// MaxExpiry, if set, caps how far in the future CreateToken will allow
// ExpiresAt to be. nil means no cap.
MaxExpiry *time.Duration
// RequireExpiry, if true, makes CreateToken reject a nil expiresAt.
// Off by default; GitHub and GitLab have both moved toward mandatory
// expiry over time, so a host application that wants that stance can
// opt in here rather than authit assuming it.
RequireExpiry bool
// AuditLogger receives security-relevant events (token creation,
// revocation). Nil means events are not recorded — see package audit.
AuditLogger audit.Logger
}
Config tunes the pat package's behavior.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements personal-access-token issuance, resolution, and revocation.
func NewService ¶
NewService constructs a Service. Config.AuditLogger may be nil, in which case audit.NoopLogger is used.
func (*Service) CreateToken ¶
func (s *Service) CreateToken(ctx context.Context, userID, name string, scopes []string, expiresAt *time.Time) (string, store.PersonalAccessToken, error)
CreateToken issues a new personal access token for userID. Returns the raw token exactly once — only its hash is persisted, so the caller must hand it to the user immediately.
func (*Service) ListTokens ¶
func (s *Service) ListTokens(ctx context.Context, userID string) ([]store.PersonalAccessToken, error)
ListTokens lists every token belonging to userID (including expired or revoked ones, so a UI can show their status — filter by ExpiresAt/ RevokedAt as needed).
type Stores ¶
type Stores struct {
Tokens store.PersonalAccessTokenStore
}
Stores groups the persistence ports the pat package needs.