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
anchorIn 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
anchorYou can set a token for a specific organization using the setToken()
method:
Asynchronous | Parameters | Returns |
---|---|---|
Yes | orgId (string), token (OrgServiceAppAuthorization) | Promise<void> |
anchorGet a Token
anchorTo retrieve a token for a specific organization, use the getToken()
method:
Asynchronous | Parameters | Returns |
---|---|---|
Yes | orgId (string) | Promise<OrgServiceAppAuthorization> |
anchorList All Tokens
anchorTo obtain a list of all stored tokens, use the listTokens()
method:
Asynchronous | Parameters | Returns |
---|---|---|
Yes | No parameters required | Promise<OrgServiceAppAuthorization[]> |
anchorDelete a Token
anchorTo delete a token for a specific organization, use the deleteToken()
method:
Asynchronous | Parameters | Returns |
---|---|---|
Yes | orgId (string) | Promise<void> |