The token manager for the BYoDS SDK.

Hierarchy

  • TokenManager

Constructors

  • Creates an instance of TokenManager.

    Example

    const tokenManager = new TokenManager('your-client-id', 'your-client-secret');
    

    Parameters

    • clientId: string

      The client ID of the service app.

    • clientSecret: string

      The client secret of the service app.

    • baseUrl: string = PRODUCTION_BASE_URL

      The base URL for the API. Defaults to PRODUCTION_BASE_URL.

    • tokenStorageAdapter: TokenStorageAdapter = ...
    • loggerConfig: LoggerConfig = DEFAULT_LOGGER_CONFIG

    Returns TokenManager

Methods

  • Update the tokens and their expiration times.

    Returns

    Example

    await tokenManager.updateServiceAppToken(tokenResponse, 'org-id');
    

    Parameters

    • data: TokenResponse

      The token response data.

    • orgId: string

      The organization ID.

    Returns Promise<void>

  • Get the service app ID.

    Returns

    Example

    const serviceAppId = tokenManager.getServiceAppId();
    

    Returns string

  • Get the service app authorization data for a given organization ID.

    Returns

    Example

    const authorization = await tokenManager.getOrgServiceAppAuthorization('org-id');
    

    Parameters

    • orgId: string

      The organization ID.

    Returns Promise<OrgServiceAppAuthorization>

  • List all stored tokens.

    Returns

    List of tokens

    Example

    const tokens = await tokenManager.listTokens();
    

    Returns Promise<OrgServiceAppAuthorization[]>

  • Delete a token for a given orgId.

    Returns

    Example

    await tokenManager.deleteToken('org-id');
    

    Parameters

    • orgId: string

      The organization ID.

    Returns Promise<void>

  • Remove all tokens stored in the TokenStorageAdapter.

    Returns

    Example

    await tokenManager.resetTokens();
    

    Returns Promise<void>

  • Retrieve a new service app token using the service app owner's personal access token(PAT).

    Returns

    await tokenManager.getServiceAppTokenUsingPAT('org-id', 'personal-access-token');

    Parameters

    • orgId: string

      The organization ID.

    • personalAccessToken: string

      The service app owner's personal access token or token from an integration that has the scope spark:applications_token.

    • headers: Record<string, string> = {}

    Returns Promise<void>

  • Refresh the access token using the refresh token.

    Returns

    await tokenManager.refreshServiceAppAccessToken('org-id');

    Parameters

    • orgId: string

      The organization ID.

    • headers: Record<string, string> = {}

    Returns Promise<void>

  • Save the service app registration using the provided refresh token. After saving, it can be fetched by using the getOrgServiceAppAuthorization method.

    Returns

    Example

    await tokenManager.saveServiceAppRegistrationData('org-id', 'refresh-token');
    

    Parameters

    • orgId: string

      The organization ID.

    • refreshToken: string

      The refresh token.

    • headers: Record<string, string> = {}

    Returns Promise<void>