import { GetJwtCallback , Jwt } from '../Jwt' ; import { IAccessToken , IAccessTokenProvider , ITokenContext } from './interfaces' ; /**
 * Implementation of  IAccessToken that calls the user-provided
 * callback function to get the JWT when requested by the clients.
  export class CallbackJwtProvider implements IAccessTokenProvider { private readonly getJwt : ( tokenContext : ITokenContext ) => Promise < Jwt > ; param { GetJwtCallback } getJwtFn - The function that will be called
     * whenever the JWT is needed. If the `getJwtFn` returns the JWT as a
     * string, it will be converted to  Jwt instance automatically.
      public constructor ( getJwtFn ) { if ( typeof getJwtFn !== 'function' ) { throw new TypeError ( '`getJwtFn` must be a function' ) ; } this . getJwt = ( context ) => Promise . resolve ( getJwtFn ( context ) ) . then ( token => typeof token === 'string' ? Jwt . fromString ( token ) : token ) ; } /**
     * Returns a `Promise` resolved with the  Jwt instance obtained
     * by the call to the  CallbackJwtProvider . getJwt . If the
     * `getJwtFn` returns the JWT as a string, it is converted to
     *  Jwt instance before returning.
     *
     *  param { ITokenContext } context returns { Promise < IAccessToken > } public getToken ( context ) { return this . getJwt ( context ) ; } }