auth

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ClientSecretEnv = "BG_CLI_CLIENT_SECRET"

Variables

View Source
var DefaultScopes = append([]string{}, KnownScopes...)

DefaultScopes are requested by auth login unless the operator opts out with an explicit --scopes list. Policy is all documented account views.

View Source
var ErrNoKeyring = errors.New("secure credential store unavailable")

ErrNoKeyring indicates the OS credential store is unavailable.

View Source
var KnownScopes = []string{
	"player-data:pet-simulator-99:inventory:read",
	"player-data:pet-simulator-99:profile:read",
	"player-data:pet-simulator-99:extendedProfile:read",
	"player-data:pet-simulator-99:itemIndex:read",
	"player-data:pet-simulator-99:trades:read",
	"player-data:pet-simulator-99:booth:read",
	"player-data:pet-simulator-99:mail:read",
}

KnownScopes are the seven documented account scopes.

Functions

func BuildAuthorizeURL

func BuildAuthorizeURL(p AuthorizeParams) (string, error)

BuildAuthorizeURL constructs the BIG Games authorize URL.

func ChallengeFromVerifier

func ChallengeFromVerifier(verifier string) string

ChallengeFromVerifier returns the S256 challenge for a verifier (tests).

func GenerateState

func GenerateState() (string, error)

GenerateState creates an unpredictable OAuth state value.

func HasAllScopes

func HasAllScopes(granted string, requested []string) bool

HasAllScopes reports whether granted contains every requested scope.

func MissingScopes

func MissingScopes(granted string, requested []string) []string

MissingScopes returns requested scopes absent from granted.

func ParseScopeList

func ParseScopeList(raw string) ([]string, error)

ParseScopeList splits a comma- or space-separated scope list.

func ScopeString

func ScopeString(scopes []string) string

ScopeString joins scopes with a single space for OAuth.

func ValidateGrantedScopes

func ValidateGrantedScopes(tr TokenResponse, requested []string) error

ValidateGrantedScopes ensures the token includes every requested scope.

func ValidateScopes

func ValidateScopes(scopes []string) error

ValidateScopes ensures every scope is a documented value.

Types

type AuthorizeParams

type AuthorizeParams struct {
	ClientID      string
	RedirectURI   string
	Scopes        []string
	State         string
	CodeChallenge string
	AuthorizeURL  string // tests may override; production uses ProductionOAuthAuthorize
}

AuthorizeParams builds the browser authorize URL.

type CallbackResult

type CallbackResult struct {
	Code  string
	State string
	Error string
	Raw   url.Values
}

CallbackResult is the one-shot OAuth redirect payload.

type ExchangeParams

type ExchangeParams struct {
	TokenURL     string // tests inject; production must be ProductionOAuthToken
	ClientID     string
	ClientSecret string
	Code         string
	RedirectURI  string
	Verifier     string
	HTTPClient   *http.Client
}

ExchangeParams are inputs for the one-time token exchange.

type KeyringStore

type KeyringStore struct {
	Service string
}

KeyringStore uses the OS credential store.

func (KeyringStore) Delete

func (k KeyringStore) Delete(profile string) error

Delete removes an access token for a profile alias.

func (KeyringStore) Get

func (k KeyringStore) Get(profile string) (string, error)

Get retrieves an access token for a profile alias.

func (KeyringStore) Set

func (k KeyringStore) Set(profile, token string) error

Set stores an access token for a profile alias.

type LoginOptions

type LoginOptions struct {
	Profile      string
	ClientID     string
	RedirectURI  string
	Scopes       []string
	NoOpen       bool
	AuthorizeURL string
	TokenURL     string
	HTTPClient   *http.Client
	TokenStore   TokenStore
	SecretSource SecretSource
	Stdout       io.Writer // unused for secrets; reserved
	Stderr       io.Writer
	OpenURL      func(string) error
	Now          func() time.Time
	CallbackWait time.Duration
}

LoginOptions configure the interactive OAuth login flow.

type LoginResult

type LoginResult struct {
	Profile   string
	Scopes    []string
	ExpiresAt time.Time
	IssuedAt  time.Time
}

LoginResult is the non-secret outcome of a successful login.

func Login

Login runs Authorization Code + PKCE against BIG Games (or injected test endpoints).

type LoopbackServer

type LoopbackServer struct {
	Listener net.Listener
	Path     string
	Timeout  time.Duration
}

LoopbackServer accepts exactly one OAuth callback on a loopback address.

func StartLoopback

func StartLoopback(redirectURI string) (*LoopbackServer, error)

StartLoopback binds 127.0.0.1 on an ephemeral or fixed port.

func (*LoopbackServer) Close

func (s *LoopbackServer) Close() error

Close releases the listener.

func (*LoopbackServer) RedirectURI

func (s *LoopbackServer) RedirectURI(path string) string

RedirectURI returns the exact registered callback URI including bound port.

func (*LoopbackServer) Wait

func (s *LoopbackServer) Wait(ctx context.Context, expectedState string) (CallbackResult, error)

Wait accepts one valid callback and shuts down.

type MemoryStore

type MemoryStore struct {
	Fail bool
	// contains filtered or unexported fields
}

MemoryStore is an in-memory TokenStore for tests. Not for production.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(profile string) error

func (*MemoryStore) Get

func (m *MemoryStore) Get(profile string) (string, error)

func (*MemoryStore) Set

func (m *MemoryStore) Set(profile, token string) error

type PKCE

type PKCE struct {
	Verifier  string
	Challenge string
	Method    string
}

PKCE holds a verifier and S256 challenge.

func GeneratePKCE

func GeneratePKCE() (PKCE, error)

GeneratePKCE creates a cryptographically random verifier and S256 challenge.

type SecretSource

type SecretSource struct {
	Env    func(string) string
	Stdin  io.Reader
	Stderr io.Writer
	IsTTY  func() bool
}

SecretSource reads the client secret without accepting CLI flags.

func (SecretSource) ReadClientSecret

func (s SecretSource) ReadClientSecret() (string, error)

ReadClientSecret returns the client secret from env, then masked prompt / stdin. Never accepts a command-line flag.

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int64  `json:"expires_in"`
	Scope       string `json:"scope"`
	Error       string `json:"error"`
	ErrorDesc   string `json:"error_description"`
}

TokenResponse is the OAuth token endpoint JSON body.

func ExchangeCode

func ExchangeCode(ctx context.Context, p ExchangeParams) (TokenResponse, error)

ExchangeCode performs a single token exchange with no redirects and no retries.

type TokenStore

type TokenStore interface {
	Set(profile, token string) error
	Get(profile string) (string, error)
	Delete(profile string) error
}

TokenStore persists access tokens. Implementations must never write plaintext files.

Jump to

Keyboard shortcuts

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