auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const ExtensionDaemonKey = "extension-daemon"

ExtensionDaemonKey stores the extension daemon's shared secret.

Variables

This section is empty.

Functions

func DeleteAllCredentials

func DeleteAllCredentials() error

func DeleteCredential

func DeleteCredential(provider string) error

func DeleteCredentials

func DeleteCredentials(providers ...string) error

func SetCredential

func SetCredential(provider string, cred *AuthCredential) error

Types

type AuthCredential

type AuthCredential struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	AccountID    string    `json:"account_id,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	Provider     string    `json:"provider"`
	AuthMethod   string    `json:"auth_method"`
	// IDToken, TokenType and Metadata round-trip a signed-in credential's
	// tokenstore.Record. Metadata may hold secrets; it is stored like tokens.
	IDToken   string            `json:"id_token,omitempty"`
	TokenType string            `json:"token_type,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
	// Revision changes on every write through the token store, which
	// compares it to fence out writers whose view is stale.
	Revision string `json:"revision,omitempty"`
}

func GetCredential

func GetCredential(provider string) (*AuthCredential, error)

func LoginPasteToken

func LoginPasteToken(provider string, r io.Reader) (*AuthCredential, error)

func (*AuthCredential) IsExpired

func (c *AuthCredential) IsExpired() bool

func (*AuthCredential) NeedsRefresh

func (c *AuthCredential) NeedsRefresh() bool

type AuthStore

type AuthStore struct {
	Credentials map[string]*AuthCredential `json:"credentials"`
}

func LoadStore

func LoadStore() (*AuthStore, error)

type TokenStore

type TokenStore struct {
	// contains filtered or unexported fields
}

TokenStore is a tokenstore.Store over an auth.json file, shared by every process that opens the same file: the launcher, the kernel and the CLI.

Writes hold the same OS lock as every other auth.json update and replace a credential only when its revision still matches. A lease is an OS lock on a per-key sidecar file, which the OS releases if its holder dies, so a refresh in one process fences out the others without a staleness guess.

func DefaultTokenStore

func DefaultTokenStore() *TokenStore

DefaultTokenStore returns the store over the Compa home's auth.json.

func OpenTokenStore

func OpenTokenStore(path string) *TokenStore

OpenTokenStore returns the store over the auth.json file at path.

func (*TokenStore) Lease

func (s *TokenStore) Lease(ctx context.Context, key string) (func(), error)

Lease blocks until it holds the exclusive refresh lease for key or ctx ends. The lease holds until release is called or the process exits.

func (*TokenStore) Load

func (s *TokenStore) Load(ctx context.Context, key string) (tokenstore.Record, error)

Load returns the current record, or tokenstore.ErrNotFound.

func (*TokenStore) ReplaceIfCurrent

func (s *TokenStore) ReplaceIfCurrent(ctx context.Context, key, revision string, record tokenstore.Record) (tokenstore.Record, error)

ReplaceIfCurrent stores record only if the stored revision is revision.

func (*TokenStore) RevokeIfCurrent

func (s *TokenStore) RevokeIfCurrent(ctx context.Context, key, revision string) error

RevokeIfCurrent removes the credential only if its revision is revision.

func (*TokenStore) Save

func (s *TokenStore) Save(ctx context.Context, key string, record tokenstore.Record) (tokenstore.Record, error)

Save stores record unconditionally, as a new sign-in does.

Jump to

Keyboard shortcuts

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