auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientFromAuthFile

func ClientFromAuthFile(ctx context.Context, authPath string) (*http.Client, error)

ClientFromAuthFile builds an authenticated HTTP client from .clasprc.json. If refresh_token exists, this function refreshes token.access_token and persists it.

func ClientFromAuthJSON added in v0.2.7

func ClientFromAuthJSON(ctx context.Context, jsonContent string) (*http.Client, error)

ClientFromAuthJSON creates an authenticated HTTP client from raw .clasprc.json content (e.g. the value of the GLASP_AUTH environment variable). Refreshed tokens are not persisted to disk.

func Config

func Config() (*oauth2.Config, error)

Config returns an OAuth2 configuration.

func ConfigFromAuthFile

func ConfigFromAuthFile(authPath string) (*oauth2.Config, error)

ConfigFromAuthFile returns an OAuth2 configuration loaded from a .clasprc.json file.

func EnsureAccessToken

func EnsureAccessToken(ctx context.Context, source Source) (*http.Client, error)

EnsureAccessToken resolves an authenticated HTTP client and refreshes token if needed.

func ImportAuthFile

func ImportAuthFile(authPath, cacheFile string) error

ImportAuthFile reads a .clasprc.json-style auth file and saves the token to cacheFile (.glasp/access.json). It returns an error if cacheFile already exists.

func Login

func Login(ctx context.Context, config *oauth2.Config) (*http.Client, error)

Login performs the OAuth2 login flow using the project-local token cache.

func LoginWithCachePath

func LoginWithCachePath(ctx context.Context, config *oauth2.Config, cacheFile string) (*http.Client, error)

LoginWithCachePath performs the OAuth2 login flow using an explicit cache file path.

func LoginWithOptions added in v0.3.0

func LoginWithOptions(ctx context.Context, config *oauth2.Config, opts LoginOptions) (*http.Client, error)

LoginWithOptions performs the OAuth2 login flow with explicit options.

func Logout

func Logout() error

Logout deletes the cached token file.

Types

type LoginOptions added in v0.3.0

type LoginOptions struct {
	// PKCE enables PKCE (Proof Key for Code Exchange) for the OAuth code exchange.
	PKCE bool
}

LoginOptions configures optional behavior of the interactive login flow.

type Source

type Source struct {
	Kind    SourceKind
	Path    string // used by SourceKindProjectCache and SourceKindAuthFile
	Content string // raw JSON content, used by SourceKindAuthJSON
}

Source represents a resolved authentication source.

func ResolveAuthSource

func ResolveAuthSource(projectRoot, authPath string) (Source, error)

ResolveAuthSource chooses auth source by CLI input. If authPath is provided, .clasprc.json is used; otherwise project-local cache is used.

type SourceKind

type SourceKind string

SourceKind identifies where authentication material is loaded from.

const (
	SourceKindProjectCache SourceKind = "project_cache"
	SourceKindAuthFile     SourceKind = "auth_file"
	// SourceKindAuthJSON is used when auth credentials are provided as raw
	// JSON content (e.g. via the GLASP_AUTH environment variable) rather
	// than a file path.
	SourceKindAuthJSON SourceKind = "auth_json"
)

Jump to

Keyboard shortcuts

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