soundcloud-api-ts - v1.13.4
    Preparing search index...

    Interface TokenProvider

    Contract for a pluggable token provider that manages OAuth token lifecycle.

    Implement this interface to integrate soundcloud-api-ts with your framework's session management, e.g. NextAuth, Clerk, Redis, or a simple in-memory store.

    class InMemoryTokenProvider implements TokenProvider {
    private _accessToken?: string;
    private _refreshToken?: string;

    getAccessToken() { return this._accessToken; }
    setTokens(access: string, refresh?: string) {
    this._accessToken = access;
    this._refreshToken = refresh;
    }
    async refreshIfNeeded(client: SoundCloudClient) {
    if (!this._refreshToken) throw new Error('No refresh token');
    const token = await client.auth.refreshUserToken(this._refreshToken);
    this.setTokens(token.access_token, token.refresh_token);
    return token.access_token;
    }
    }

    docs/auth-guide.md

    interface TokenProvider {
        getAccessToken(): string | Promise<string | undefined> | undefined;
        refreshIfNeeded(client: SoundCloudClient): string | Promise<string>;
        setTokens(accessToken: string, refreshToken?: string): void | Promise<void>;
    }
    Index

    Methods

    • Returns the current access token, or undefined if none is stored.

      Returns string | Promise<string | undefined> | undefined

    • Persist new tokens (called after a successful token grant or refresh).

      Parameters

      • accessToken: string
      • OptionalrefreshToken: string

      Returns void | Promise<void>