auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoToken is returned when no token is stored in the keyring.
	ErrNoToken       = errors.New("no token found")
	ErrNoCredentials = errors.New("no oauth credentials configured")
)
View Source
var ErrNotAuthenticated = errors.New("not authenticated")

Functions

func Authorize

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

func DefaultRedirectURI

func DefaultRedirectURI(port int) string

func IsKeychainLockedError

func IsKeychainLockedError(msg string) bool

func ResolveRedirectURI

func ResolveRedirectURI(creds OAuthCredentials, port int) string

Types

type AuthorizeOptions

type AuthorizeOptions struct {
	Manual  bool
	Timeout time.Duration
	Port    int
}

type KeyringStore

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

func (*KeyringStore) CredentialsExists

func (s *KeyringStore) CredentialsExists() (bool, error)

func (*KeyringStore) DeleteCredentials

func (s *KeyringStore) DeleteCredentials() error

func (*KeyringStore) DeleteToken

func (s *KeyringStore) DeleteToken() error

func (*KeyringStore) GetCredentials

func (s *KeyringStore) GetCredentials() (OAuthCredentials, error)

func (*KeyringStore) GetToken

func (s *KeyringStore) GetToken() (Token, error)

func (*KeyringStore) SetCredentials

func (s *KeyringStore) SetCredentials(creds OAuthCredentials) error

func (*KeyringStore) SetToken

func (s *KeyringStore) SetToken(tok Token) error

type OAuthCredentials

type OAuthCredentials struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	RedirectURI  string `json:"redirect_uri,omitempty"`
}

type OAuthTokenSource

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

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

func NewOAuthTokenSource

func NewOAuthTokenSource(store Store, creds OAuthCredentials) *OAuthTokenSource

NewOAuthTokenSource creates an OAuth token source using stored credentials.

func (*OAuthTokenSource) Invalidate

func (ts *OAuthTokenSource) Invalidate()

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

func (*OAuthTokenSource) Token

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

Token returns a valid access token, refreshing if necessary.

type RefreshTokenSource

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

RefreshTokenSource uses a refresh token directly (used during login).

func NewRefreshTokenSource

func NewRefreshTokenSource(creds OAuthCredentials, refreshToken string) *RefreshTokenSource

NewRefreshTokenSource creates a token source from a refresh token directly.

func (*RefreshTokenSource) Token

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

Token returns an access token by exchanging the refresh token.

type Store

type Store interface {
	SetToken(tok Token) error
	GetToken() (Token, error)
	DeleteToken() error
	SetCredentials(creds OAuthCredentials) error
	GetCredentials() (OAuthCredentials, error)
	DeleteCredentials() error
	CredentialsExists() (bool, error)
}

func OpenDefault

func OpenDefault() (Store, error)

type TestTokenSource

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

TestTokenSource provides a static token from the test token or environment.

func NewTestTokenSource

func NewTestTokenSource(store Store) *TestTokenSource

func (*TestTokenSource) Token

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

Token returns the access token from env or keyring.

type Token

type Token struct {
	TestToken    string    `json:"test_token,omitempty"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
}

Jump to

Keyboard shortcuts

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