UNPKG

@trimble-oss/trimble-id

Version:

Trimble Identity SDK for JavaScript/TypeScript

48 lines (47 loc) 1.76 kB
/** * Copyright (c) Trimble Inc. */ import { TokenProvider } from '../interfaces/TokenProvider'; import { EndpointProvider } from '../interfaces/EndpointProvider'; /** * The Client Credentials grant is used when applications request an access token to access their own resources. * */ export default class ClientCredentialTokenProvider implements TokenProvider { private readonly _endpointProvider; private readonly _clientId; private readonly _clientSecret; private _scopes; private _accessToken; private _tokenExpiry; private readonly _httpClient; /** * Public constructor for ClientCredentialTokenProvider class * * @param endpointProvider - An endpoint provider that provides the URL for the Trimble Identity token endpoint. * It can be OpenIdEndpointProvider/FixedEndpointProvider * @param clientId - The client id for the calling application * @param clientSecret - The client secret for the calling application */ constructor(endpointProvider: EndpointProvider, clientId: string, clientSecret: string); /** * Fluent extension to add scopes * * @param scopes - The scopes to add to the token provider */ WithScopes(scopes: string[]): this; /** * Retrieves an access token for the application * * @returns A promise that resolves to the value of the access token on completion * @throws Thrown when a token endpoint is not provided by the endpoint provider * @throws Thrown when a call to the token endpoint fails */ RetrieveToken(): Promise<string>; /** * Internal method to refresh the access token * * @returns Promise that resolves when token is refreshed */ private _refreshToken; }