Documentation
¶
Index ¶
- Constants
- func DeleteCredentials() error
- func HasCredentials() bool
- type Credentials
- func (c *Credentials) GetValidToken() (string, error)
- func (c *Credentials) IsExpired() bool
- func (c *Credentials) NeedsValidation() bool
- func (c *Credentials) Save() error
- func (c *Credentials) Update(accessToken string, expiresAt time.Time, email, orgName string) error
- func (c *Credentials) UpdateValidatedAt() error
Constants ¶
const ExpiryBuffer = time.Minute
ExpiryBuffer is subtracted from expiry time to refresh tokens early.
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) UpdateValidatedAt ¶
func (c *Credentials) UpdateValidatedAt() error
UpdateValidatedAt updates the last validated timestamp and saves to disk.