auth

package
v0.53.8-nightly Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAllCredentials

func ClearAllCredentials() error

ClearAllCredentials removes all stored credentials

func FormatWalletAddress

func FormatWalletAddress(address string) string

FormatWalletAddress formats a wallet address consistently

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString generates a cryptographically secure random string

func GetCredentialsPath

func GetCredentialsPath() (string, error)

GetCredentialsPath returns the path to the credentials file

func GetDefaultGatewayURL

func GetDefaultGatewayURL() string

GetDefaultGatewayURL returns the default gateway URL from environment or fallback

func HasValidCredentials

func HasValidCredentials() (bool, error)

HasValidCredentials checks if there are valid credentials for the default gateway

func HasValidEnhancedCredentials

func HasValidEnhancedCredentials() (bool, error)

HasValidEnhancedCredentials checks if there are valid credentials for the default gateway

func SaveCredentialsForDefaultGateway

func SaveCredentialsForDefaultGateway(creds *Credentials) error

SaveCredentialsForDefaultGateway saves credentials for the default gateway

func ValidateWalletAddress

func ValidateWalletAddress(address string) bool

ValidateWalletAddress validates that a wallet address is properly formatted

Types

type AuthChoice

type AuthChoice int

AuthChoice represents user's choice during authentication

const (
	AuthChoiceUseCredential AuthChoice = iota
	AuthChoiceAddCredential
	AuthChoiceLogout
	AuthChoiceExit
)

type AuthServer

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

AuthServer handles the local HTTP server for receiving auth callbacks

func NewAuthServer

func NewAuthServer() (*AuthServer, error)

NewAuthServer creates a new authentication callback server

func (*AuthServer) Close

func (as *AuthServer) Close() error

Close shuts down the authentication server

func (*AuthServer) GetPort

func (as *AuthServer) GetPort() int

GetPort returns the port the server is listening on

type CredentialStore

type CredentialStore struct {
	Gateways map[string]*Credentials `json:"gateways"`
	Version  string                  `json:"version"`
}

CredentialStore manages credentials for multiple gateways

func LoadCredentials

func LoadCredentials() (*CredentialStore, error)

LoadCredentials loads credentials from ~/.debros/credentials.json

func (*CredentialStore) GetCredentialsForGateway

func (store *CredentialStore) GetCredentialsForGateway(gatewayURL string) (*Credentials, bool)

GetCredentialsForGateway returns credentials for a specific gateway URL

func (*CredentialStore) RemoveCredentialsForGateway

func (store *CredentialStore) RemoveCredentialsForGateway(gatewayURL string)

RemoveCredentialsForGateway removes credentials for a specific gateway URL

func (*CredentialStore) SaveCredentials

func (store *CredentialStore) SaveCredentials() error

SaveCredentials saves credentials to ~/.debros/credentials.json

func (*CredentialStore) SetCredentialsForGateway

func (store *CredentialStore) SetCredentialsForGateway(gatewayURL string, creds *Credentials)

SetCredentialsForGateway stores credentials for a specific gateway URL

type Credentials

type Credentials struct {
	APIKey       string    `json:"api_key"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	Namespace    string    `json:"namespace"`
	UserID       string    `json:"user_id,omitempty"`
	Wallet       string    `json:"wallet,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	IssuedAt     time.Time `json:"issued_at"`
	LastUsedAt   time.Time `json:"last_used_at,omitempty"`
	Plan         string    `json:"plan,omitempty"`
}

Credentials represents authentication credentials for a specific gateway

func GetOrPromptForCredentials

func GetOrPromptForCredentials(gatewayURL string) (*Credentials, error)

GetOrPromptForCredentials handles the complete authentication flow

func GetValidEnhancedCredentials

func GetValidEnhancedCredentials() (*Credentials, error)

GetValidEnhancedCredentials returns valid credentials for the default gateway

func PerformWalletAuthentication

func PerformWalletAuthentication(gatewayURL string) (*Credentials, error)

PerformWalletAuthentication starts the complete wallet authentication flow

func (*Credentials) IsExpired

func (creds *Credentials) IsExpired() bool

IsExpired checks if credentials are expired

func (*Credentials) IsValid

func (creds *Credentials) IsValid() bool

IsValid checks if credentials are valid (not empty and not expired)

func (*Credentials) UpdateLastUsed

func (creds *Credentials) UpdateLastUsed()

UpdateLastUsed updates the last used timestamp

type EnhancedCredentialStore

type EnhancedCredentialStore struct {
	Gateways map[string]*GatewayCredentials `json:"gateways"`
	Version  string                         `json:"version"`
}

EnhancedCredentialStore manages multiple credentials per gateway

func LoadEnhancedCredentials

func LoadEnhancedCredentials() (*EnhancedCredentialStore, error)

LoadEnhancedCredentials loads the enhanced credential store, with migration support from legacy v2.0 format

func (*EnhancedCredentialStore) AddCredential

func (store *EnhancedCredentialStore) AddCredential(gatewayURL string, creds *Credentials)

AddCredential adds a new credential for the gateway

func (*EnhancedCredentialStore) ClearAllCredentials

func (store *EnhancedCredentialStore) ClearAllCredentials()

ClearAllCredentials removes all credentials

func (*EnhancedCredentialStore) DisplayCredentialMenu

func (store *EnhancedCredentialStore) DisplayCredentialMenu(gatewayURL string) (AuthChoice, int, error)

DisplayCredentialMenu shows the interactive credential selection menu

func (*EnhancedCredentialStore) GetDefaultCredential

func (store *EnhancedCredentialStore) GetDefaultCredential(gatewayURL string) *Credentials

GetDefaultCredential returns the default credential for a gateway

func (*EnhancedCredentialStore) Save

func (store *EnhancedCredentialStore) Save() error

Save saves the enhanced credential store

func (*EnhancedCredentialStore) SetDefaultCredential

func (store *EnhancedCredentialStore) SetDefaultCredential(gatewayURL string, index int) bool

SetDefaultCredential sets the default credential by index

type GatewayCredentials

type GatewayCredentials struct {
	Credentials   []*Credentials `json:"credentials"`
	DefaultIndex  int            `json:"default_index"`
	LastUsedIndex int            `json:"last_used_index"`
}

GatewayCredentials holds multiple credentials for a single gateway

type WalletAuthResult

type WalletAuthResult struct {
	APIKey       string `json:"api_key"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Namespace    string `json:"namespace"`
	Wallet       string `json:"wallet"`
	Plan         string `json:"plan,omitempty"`
	ExpiresAt    string `json:"expires_at,omitempty"`
}

WalletAuthResult represents the result of wallet authentication

Jump to

Keyboard shortcuts

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