Documentation
¶
Overview ¶
Package oauth provides OAuth 2.0 authentication support for Longbridge OpenAPI.
Use OAuth by setting it on config (like the Rust SDK). The token is stored internally and in ~/.longbridge-openapi/tokens/<client_id>; it is refreshed automatically when expired. Do not use or expose OAuthToken.
Example ¶
o := oauth.New("your-client-id").
OnOpenURL(func(url string) { fmt.Println("Please visit:", url) })
if err := o.Build(context.Background()); err != nil {
log.Fatal(err)
}
cfg, _ := config.New(config.WithOAuthClient(o))
tctx, _ := trade.NewFromCfg(cfg)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OAuth ¶
type OAuth struct {
// contains filtered or unexported fields
}
OAuth is the OAuth 2.0 client for Longbridge OpenAPI. Use New and Build, then pass to config via config.WithOAuthClient(o). AccessToken(ctx) is used by the HTTP client to get a valid token (auto-refresh).
func NewWithBaseURL ¶
NewWithBaseURL creates a new OAuth client with a custom base URL (e.g. for tests).
func (*OAuth) AccessToken ¶
AccessToken returns a valid access token, refreshing it if expired or soon to expire. The HTTP client calls this when OAuth is set on config.
func (*OAuth) Build ¶
Build loads a token from ~/.longbridge-openapi/tokens/<client_id> or runs the authorization flow, then stores the token in memory and on disk. Call this once before passing the OAuth to config. If a token exists and is expired, it is refreshed automatically.
func (*OAuth) OnOpenURL ¶
OnOpenURL sets a callback for the authorization URL (e.g. open in browser or print).
func (*OAuth) WithCallbackPort ¶
WithCallbackPort sets the local callback port (default: 60355).