Documentation
¶
Index ¶
- Constants
- Variables
- func BuildAuthorizeURL(p AuthorizeParams) (string, error)
- func ChallengeFromVerifier(verifier string) string
- func GenerateState() (string, error)
- func HasAllScopes(granted string, requested []string) bool
- func MissingScopes(granted string, requested []string) []string
- func ParseScopeList(raw string) ([]string, error)
- func ScopeString(scopes []string) string
- func ValidateGrantedScopes(tr TokenResponse, requested []string) error
- func ValidateScopes(scopes []string) error
- type AuthorizeParams
- type CallbackResult
- type ExchangeParams
- type KeyringStore
- type LoginOptions
- type LoginResult
- type LoopbackServer
- type MemoryStore
- type PKCE
- type SecretSource
- type TokenResponse
- type TokenStore
Constants ¶
const ClientSecretEnv = "BG_CLI_CLIENT_SECRET"
Variables ¶
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.
var ErrNoKeyring = errors.New("secure credential store unavailable")
ErrNoKeyring indicates the OS credential store is unavailable.
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 ¶
ChallengeFromVerifier returns the S256 challenge for a verifier (tests).
func GenerateState ¶
GenerateState creates an unpredictable OAuth state value.
func HasAllScopes ¶
HasAllScopes reports whether granted contains every requested scope.
func MissingScopes ¶
MissingScopes returns requested scopes absent from granted.
func ParseScopeList ¶
ParseScopeList splits a comma- or space-separated scope list.
func ScopeString ¶
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 ¶
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 ¶
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 ¶
LoginResult is the non-secret outcome of a successful login.
func Login ¶
func Login(ctx context.Context, opt LoginOptions) (LoginResult, *redact.Secrets, error)
Login runs Authorization Code + PKCE against BIG Games (or injected test endpoints).
type LoopbackServer ¶
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) 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) Set ¶
func (m *MemoryStore) Set(profile, token string) error
type PKCE ¶
PKCE holds a verifier and S256 challenge.
func GeneratePKCE ¶
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.