UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

37 lines (36 loc) 1.4 kB
import { Logger } from '../Logger'; import { Authed } from '../types/Authed'; import BaseAuthProvider from './BaseAuthProvider'; /** * Authenticates with the a2w API using an oauth code. * * The initial grant exchanges the supplied `code` at `/auth/oauth/token`. The shared * {@link BaseAuthProvider} machinery handles caching, in-flight dedup, clock-skew * margin, and refresh-token exchange via `/auth/apiRefresh` — so an expired token is * refreshed without re-spending the original (one-shot) code. */ export default class OAuthProvider extends BaseAuthProvider { private app; private code; /** * Constructor. * * @param app The ID of the app requesting authentication. * @param code The code that was received from the oauth. * @param logger The logger to use. * @param baseUrl The API base URL to send the grant request to. */ constructor(app: string, code?: string, logger?: Logger, baseUrl?: string); /** * Returns a URL to get an oauth code. * * @param redirectUrl The URL to redirect to after the oauth code is received. * @param scopes The requested scopes. * @param state Any value, it will be returned in the redirect. */ getCodeUrl: (redirectUrl: string, scopes: string[], state: string) => string; /** * @inheritdoc */ protected fetchAuthed: () => Promise<Authed>; }