Documentation
¶
Overview ¶
Package auth handles NEPSE API authentication using embedded WASM to decode obfuscated tokens returned by the NEPSE API.
Index ¶
Constants ¶
const DefaultTokenTTL = 45 * time.Second
DefaultTokenTTL defines when to proactively refresh tokens. NEPSE tokens expire after ~60 seconds; we refresh at 45s to avoid mid-request expiration.
Variables ¶
This section is empty.
Functions ¶
func SetAuthHeader ¶
SetAuthHeader adds the NEPSE-specific "Salter" authorization header.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides thread-safe access to NEPSE authentication tokens. It uses singleflight to prevent thundering herd when multiple goroutines request tokens simultaneously during refresh.
func NewManager ¶
NewManager creates a Manager with the embedded WASM token parser.
func (*Manager) AccessToken ¶
AccessToken returns a valid access token, refreshing if expired.
func (*Manager) ForceUpdate ¶
ForceUpdate invalidates the cache and fetches fresh tokens. Used after receiving 401 to force re-authentication.
type NepseHTTP ¶
type NepseHTTP interface {
Token(ctx context.Context) (*TokenResponse, error)
}
NepseHTTP abstracts HTTP calls needed for token acquisition.
type Salts ¶ added in v0.1.2
Salts holds the 5 salt values from the NEPSE token response. These are used to compute POST payload IDs for certain endpoints.
type TokenResponse ¶
type TokenResponse struct {
Salt1 int `json:"salt1"`
Salt2 int `json:"salt2"`
Salt3 int `json:"salt3"`
Salt4 int `json:"salt4"`
Salt5 int `json:"salt5"`
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
ServerTime int64 `json:"serverTime"`
}
TokenResponse is the JSON structure from /api/authenticate/prove. Salt values are used to compute which characters to strip from tokens.