Longbridge OpenAPI SDK
    Preparing search index...

    Class OAuth

    OAuth 2.0 client handle for Longbridge OpenAPI

    Obtain an instance via OAuth.build(...). Pass it to Config.fromOAuth(...) or HttpClient.fromOAuth(...).

    const { OAuth, Config } = require('longbridge');

    const oauth = await OAuth.build('your-client-id', (_, url) => {
    console.log('Open:', url);
    });
    const config = Config.fromOAuth(oauth);
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Build an OAuth 2.0 client.

      If a valid token is already cached on disk (~/.longbridge/openapi/tokens/<clientId>) it is reused; otherwise the browser authorization flow is started and onOpenUrl is called with the authorization URL.

      Parameters

      • clientId: string

        OAuth 2.0 client ID from the Longbridge developer portal

      • onOpenUrl: (err: Error | null, arg: string) => void

        Called with the authorization URL; open it in a browser or print it however you like

      • OptionalcallbackPort: number | null

        TCP port for the local callback server (default: 60355). Must match one of the redirect URIs registered for the client.

      Returns Promise<OAuth>

      OAuth handle that can be passed to Config.fromOAuth or HttpClient.fromOAuth