auth

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAuthenticated = errors.New("not authenticated")

Functions

func Authorize

func Authorize(ctx context.Context, opts AuthorizeOptions) (string, error)

func EnsureCertificate

func EnsureCertificate() (certPath, keyPath string, err error)

EnsureCertificate returns paths to cert and key files, generating them if needed.

func GetAuthenticatedEmail

func GetAuthenticatedEmail(client string) (string, error)

GetAuthenticatedEmail returns the email for the authenticated account, or error if not authenticated.

func IsKeychainLockedError

func IsKeychainLockedError(msg string) bool

func ParseTokenKey

func ParseTokenKey(k string) (client, email string, ok bool)

Types

type AuthorizeOptions

type AuthorizeOptions struct {
	Manual       bool
	ForceConsent bool
	Timeout      time.Duration
	Client       string
}

type KeyringStore

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

func (*KeyringStore) DeleteToken

func (s *KeyringStore) DeleteToken(client, email string) error

func (*KeyringStore) GetToken

func (s *KeyringStore) GetToken(client, email string) (Token, error)

func (*KeyringStore) Keys

func (s *KeyringStore) Keys() ([]string, error)

func (*KeyringStore) ListTokens

func (s *KeyringStore) ListTokens() ([]Token, error)

func (*KeyringStore) SetToken

func (s *KeyringStore) SetToken(client, email string, tok Token) error

type RefreshTokenSource added in v0.1.4

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

RefreshTokenSource is a simple token source that uses a refresh token directly. Used during initial login before we know the user's email.

func NewRefreshTokenSource added in v0.1.4

func NewRefreshTokenSource(client, refreshToken string) *RefreshTokenSource

NewRefreshTokenSource creates a token source from a refresh token directly.

func (*RefreshTokenSource) Token added in v0.1.4

func (ts *RefreshTokenSource) Token() (*oauth2.Token, error)

Token returns an access token by exchanging the refresh token.

type Store

type Store interface {
	Keys() ([]string, error)
	SetToken(client, email string, tok Token) error
	GetToken(client, email string) (Token, error)
	DeleteToken(client, email string) error
	ListTokens() ([]Token, error)
}

func OpenDefault

func OpenDefault() (Store, error)

type Token

type Token struct {
	Client       string    `json:"client,omitempty"`
	Email        string    `json:"email"`
	Scopes       []string  `json:"scopes,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
	RefreshToken string    `json:"-"`
}

type TokenSource

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

TokenSource provides OAuth2 tokens with lazy refresh on 401. Access tokens are kept in memory only; refresh tokens are stored in keyring.

func NewTokenSource

func NewTokenSource(client, email string, store Store) *TokenSource

func (*TokenSource) Invalidate

func (ts *TokenSource) Invalidate()

Invalidate marks the current access token as invalid, forcing a refresh on next Token() call.

func (*TokenSource) Token

func (ts *TokenSource) Token() (*oauth2.Token, error)

Token returns a valid access token, refreshing if necessary.

Jump to

Keyboard shortcuts

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