auth

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasDisplay

func HasDisplay() bool

HasDisplay reports whether the current environment likely has a graphical display available (i.e. not a headless server or SSH session).

func LoadCredentials

func LoadCredentials() (credentials, error)

LoadCredentials reads the full credentials struct from disk.

func LoadHubURL added in v0.3.0

func LoadHubURL() (string, error)

LoadHubURL reads the hub URL from saved credentials.

func LoadRefreshToken

func LoadRefreshToken() (string, error)

LoadRefreshToken reads the refresh token from credentials.

func LoadToken

func LoadToken() (string, error)

LoadToken reads the access token from ~/.cllmhub/credentials.

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens the given URL in the user's default browser.

func RemoveCredentials

func RemoveCredentials() error

RemoveCredentials deletes the credentials file.

func RevokeToken

func RevokeToken(ctx context.Context, hubURL, refreshToken string) error

RevokeToken revokes a refresh token server-side (RFC 7009).

func SaveCredentials

func SaveCredentials(creds credentials) error

SaveCredentials writes the credentials struct to disk.

func SaveOAuthCredentials

func SaveOAuthCredentials(hubURL, accessToken, refreshToken, tokenType string, expiresAt time.Time) error

SaveOAuthCredentials stores OAuth tokens in ~/.cllmhub/credentials.

Types

type DeviceAuthResponse

type DeviceAuthResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

DeviceAuthResponse is the response from the device authorization endpoint.

func StartDeviceAuth

func StartDeviceAuth(ctx context.Context, hubURL string) (*DeviceAuthResponse, error)

StartDeviceAuth initiates the OAuth 2.0 device authorization flow.

type PermanentOAuthError added in v0.4.3

type PermanentOAuthError struct {
	Code        string
	Description string
}

PermanentOAuthError represents an OAuth error that will not succeed on retry (e.g. invalid_grant, invalid_client).

func (*PermanentOAuthError) Error added in v0.4.3

func (e *PermanentOAuthError) Error() string

type TokenManager

type TokenManager struct {

	// Dead is closed when the token manager can no longer refresh tokens.
	Dead chan struct{}
	// contains filtered or unexported fields
}

TokenManager handles automatic access token refresh in the background. It is safe for concurrent use.

func NewTokenManager

func NewTokenManager(hubURL, accessToken, refreshToken string, expiresAt time.Time) *TokenManager

NewTokenManager creates a TokenManager that will refresh the access token 5 minutes before expiry. Call Stop() when done.

func ResolveTokenManager

func ResolveTokenManager(hubURL string) (string, *TokenManager, error)

ResolveTokenManager loads OAuth credentials from disk and returns a TokenManager for automatic background refresh.

func (*TokenManager) AccessToken

func (tm *TokenManager) AccessToken() string

AccessToken returns the current access token.

func (*TokenManager) Stop

func (tm *TokenManager) Stop()

Stop shuts down the background refresh goroutine.

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

TokenResponse is the response from the token endpoint.

func PollForToken

func PollForToken(ctx context.Context, hubURL string, dar *DeviceAuthResponse) (*TokenResponse, error)

PollForToken polls the token endpoint until the user approves, denies, or the code expires.

func RefreshAccessToken

func RefreshAccessToken(ctx context.Context, hubURL, refreshToken string) (*TokenResponse, error)

RefreshAccessToken exchanges a refresh token for a new access token.

Jump to

Keyboard shortcuts

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