auth

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ExpiryBuffer = time.Minute

ExpiryBuffer is subtracted from expiry time to refresh tokens early.

View Source
const ValidationInterval = 15 * time.Minute

ValidationInterval is how often we should validate the token with the server.

Variables

This section is empty.

Functions

func DeleteCredentials

func DeleteCredentials() error

DeleteCredentials removes the credentials file.

func HasCredentials

func HasCredentials() bool

HasCredentials returns whether credentials exist on disk.

Types

type Credentials

type Credentials struct {
	AccessToken      string    `json:"access_token"`
	RefreshToken     string    `json:"refresh_token,omitempty"`
	ExpiresAt        time.Time `json:"expires_at"`
	Email            string    `json:"email,omitempty"`
	OrganizationName string    `json:"organization_name,omitempty"`
	LastValidatedAt  time.Time `json:"last_validated_at,omitempty"`
}

Credentials holds OAuth tokens for API authentication.

func LoadCredentials

func LoadCredentials() (*Credentials, error)

LoadCredentials reads credentials from disk.

func (*Credentials) GetValidToken

func (c *Credentials) GetValidToken() (string, error)

GetValidToken returns the access token if valid, or an error if expired.

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

IsExpired returns whether the access token is expired or about to expire.

func (*Credentials) NeedsValidation

func (c *Credentials) NeedsValidation() bool

NeedsValidation returns whether the token should be validated with the server. Returns true if never validated or last validation was more than ValidationInterval ago.

func (*Credentials) Save

func (c *Credentials) Save() error

Save writes credentials to disk with secure permissions.

func (*Credentials) Update

func (c *Credentials) Update(accessToken string, expiresAt time.Time, email, orgName string) error

Update updates credentials with new values and saves to disk.

func (*Credentials) UpdateValidatedAt

func (c *Credentials) UpdateValidatedAt() error

UpdateValidatedAt updates the last validated timestamp and saves to disk.

Jump to

Keyboard shortcuts

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