auth

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAuthTimeout is returned when authentication times out
	ErrAuthTimeout = stderrors.New("authentication timed out after 5 minutes")
	// ErrAuthCancelled is returned when authentication is canceled by the user
	ErrAuthCancelled = stderrors.New("authentication canceled")
)

Custom error types for better error handling

Functions

func GetAuthPath added in v0.16.0

func GetAuthPath() string

GetAuthPath returns the path to the auth file (delegates to config package)

Types

type AccountToken

type AccountToken struct {
	AccountID    string    `json:"account_id"`
	AccountName  string    `json:"account_name"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	TokenType    string    `json:"token_type"`
	ExpiresIn    int       `json:"expires_in"`
	ObtainedAt   time.Time `json:"obtained_at"`
}

AccountToken represents token data for a specific account

type AuthStore

type AuthStore struct {
	DefaultAccount string                  `json:"default_account"`
	Accounts       map[string]AccountToken `json:"accounts"`
}

AuthStore manages authentication tokens

type Client

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

Client handles OAuth2 authentication

func NewClient

func NewClient(clientID, clientSecret string) *Client

NewClient creates a new auth client

func (*Client) GetAccounts

func (c *Client) GetAccounts() map[string]AccountToken

GetAccounts returns all authenticated accounts

func (*Client) GetDefaultAccount

func (c *Client) GetDefaultAccount() string

GetDefaultAccount returns the default account ID

func (*Client) GetToken

func (c *Client) GetToken(accountID string) (*AccountToken, error)

GetToken returns a valid token for the specified account

func (*Client) Login

func (c *Client) Login(ctx context.Context) (*AccountToken, error)

Login performs the OAuth2 authentication flow

func (*Client) Logout

func (c *Client) Logout(accountID string) error

Logout removes stored credentials

func (*Client) SetDefaultAccount

func (c *Client) SetDefaultAccount(accountID string) error

SetDefaultAccount sets the default account

type TokenData

type TokenData struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	TokenType    string    `json:"token_type"`
	ExpiresIn    int       `json:"expires_in"`
	ObtainedAt   time.Time `json:"obtained_at"`
}

TokenData represents the stored OAuth token information

Jump to

Keyboard shortcuts

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