auth

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLIKeyName

func CLIKeyName(username string) string

CLIKeyName scopes the key name to the user and machine that created it, so two people (or two machines) sharing an account don't revoke each other's CLI keys on login. The email domain and FQDN suffix are dropped, and the remainder is truncated as needed, to stay within maxKeyNameLen.

func DeleteCredentials

func DeleteCredentials() error

func OpenBrowser

func OpenBrowser(url string) error

func SaveCredentials

func SaveCredentials(creds *Credentials) error

Types

type Credentials

type Credentials struct {
	APIKey      string `json:"api_key"`
	Source      string `json:"source"`
	CreatedAt   string `json:"created_at"`
	Email       string `json:"email,omitempty"`
	AccountName string `json:"account_name,omitempty"`
}

func LoadCredentials

func LoadCredentials() (*Credentials, error)

type OAuthConfig

type OAuthConfig struct {
	BaseURL string
}

func DefaultOAuthConfig

func DefaultOAuthConfig() OAuthConfig

type OAuthResult

type OAuthResult struct {
	APIKey      string
	AccountName string
	// CleanupStaleKeys removes API keys left by earlier CLI logins. It is
	// never nil and must be called only after APIKey has been validated and
	// persisted, so a failure in between cannot revoke the previous key while
	// leaving no usable replacement.
	CleanupStaleKeys func()
}

func RunOAuthFlow

func RunOAuthFlow(ctx context.Context, cfg OAuthConfig) (*OAuthResult, error)

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Account  string `json:"account"`
}

func ValidateAPIKey

func ValidateAPIKey(ctx context.Context, apiKey string) (*UserInfo, error)

func ValidateAccessToken

func ValidateAccessToken(ctx context.Context, accessToken string) (*UserInfo, error)

func ValidateToken

func ValidateToken(ctx context.Context, token, tokenLabel string) (*UserInfo, error)

ValidateToken calls the whoami endpoint with the given bearer token. tokenLabel names the credential in error messages (e.g. "API key", "access token"), since the endpoint accepts both an API key and an OAuth access token.

Jump to

Keyboard shortcuts

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