CreateBlogSupport
Log inSign up
Home
Create
  • Authentication
  • Login with Webex
  • AI Assistant for Developers
  • Bots
  • Embedded Apps
  • Integrations
  • Service Apps
  • Instant Connect
  • Workspace Integrations
  • Bring Your Own Datasource
  • Suite Sandbox
  • Contact Center Sandbox
  • Guest to Guest Sandbox
  • Submit Your App
  • Tutorials

Create

Token Storage Adapter

This article provides a detailed introduction to the Token Storage Adapter in the BYoDS Node.js SDK, covering the implementation and usage of the TokenStorageAdapter class.

The TokenStorageAdapter is an interface that defines methods for storing, retrieving, and managing service app tokens. The InMemoryTokenStorageAdapter is the default implementation of this interface that stores tokens in memory.

To learn more about service apps and tokens, see Service Apps

anchorUsing the Token Storage Adapter

anchor

In order to leverage the TokenStorageAdapter, developers can extend the interface by creating their own custom adapter to connect to various databases or use the default InMemoryTokenStorageAdapter.

Here's an example of how to create a custom token storage adapter:

import { TokenStorageAdapter, OrgServiceAppAuthorization } from '@webex/byods';

class CustomTokenStorageAdapter implements TokenStorageAdapter {
  async setToken(orgId: string, token: OrgServiceAppAuthorization): Promise<void> {
    // Implement logic to store token in your database
  }

  async getToken(orgId: string): Promise<OrgServiceAppAuthorization | null> {
    // Implement logic to retrieve token from your database
  }

  async listTokens(): Promise<OrgServiceAppAuthorization[]> {
    // Implement logic to list all tokens from your database
  }

  async deleteToken(orgId: string): Promise<void> {
    // Implement logic to delete token from your database
  }

  async resetTokens(): Promise<void> {
    // Implement logic to reset all tokens in your database
  }
} 

We strongly recommend you encrypt your tokens.

In order to use this custom TokenStorageAdapter, initialize the BYODS object:

const customTokenStorageAdapter = new CustomTokenStorageAdapter();
const sdk = new BYODS({
  clientId: '<your-client-id>',
  clientSecret: '<your-client-secret>',
  tokenStorageAdapter: customTokenStorageAdapter,
});

To use the default InMemoryTokenStorageAdapter, simply pass undefined as the argument for the tokenStorageAdapter:

const sdk = new BYODS({
  clientId: '<your-client-id>',
  clientSecret: '<your-client-secret>',
  tokenStorageAdapter: undefined,
});

For more information on creating the BYODS config, see Quickstart Guide.

anchorSet a Token

anchor

You can set a token for a specific organization using the setToken() method:

AsynchronousParametersReturns
YesorgId (string), token (OrgServiceAppAuthorization)Promise<void>

anchorGet a Token

anchor

To retrieve a token for a specific organization, use the getToken() method:

AsynchronousParametersReturns
YesorgId (string)Promise<OrgServiceAppAuthorization>

anchorList All Tokens

anchor

To obtain a list of all stored tokens, use the listTokens() method:

AsynchronousParametersReturns
YesNo parameters requiredPromise<OrgServiceAppAuthorization[]>

anchorDelete a Token

anchor

To delete a token for a specific organization, use the deleteToken() method:

AsynchronousParametersReturns
YesorgId (string)Promise<void>

anchorReset All Tokens

anchor

To remove all tokens stored in the InMemoryTokenStorageAdapter, use the resetTokens() method:

AsynchronousParametersReturns
YesNo parameters requiredPromise<void>

anchorOrgServiceAppAuthorization Interface

anchor

This interface represents the authorization details for a service app within an organization. It includes the following properties:

interface OrgServiceAppAuthorization {
  orgId: string;
  serviceAppToken: ServiceAppToken;
}

anchorServiceAppToken Interface

anchor

This interface represents the token details for a service app. It includes the following properties:

interface ServiceAppToken {
  accessToken: string;
  refreshToken: string;
  expiresAt: Date;
  refreshAccessTokenExpiresAt: Date;
}
In This Article
  • Using the Token Storage Adapter
  • Set a Token
  • Get a Token
  • List All Tokens
  • Delete a Token
  • Reset All Tokens
  • OrgServiceAppAuthorization Interface
  • ServiceAppToken Interface

Connect

Support

Developer Community

Developer Events

Contact Sales

Handy Links

Webex Ambassadors

Webex App Hub

Resources

Open Source Bot Starter Kits

Download Webex

DevNet Learning Labs

Terms of Service

Privacy Policy

Cookie Policy

Trademarks

© 2025 Cisco and/or its affiliates. All rights reserved.