@trimble-oss/trimble-id
Version:
Trimble Identity SDK for JavaScript/TypeScript
46 lines (45 loc) • 1.96 kB
TypeScript
/**
* Copyright (c) Trimble Inc.
*/
import { TokenProvider } from '../interfaces/TokenProvider';
import { EndpointProvider } from '../interfaces/EndpointProvider';
/**
* The On Behalf grant flow allows an application to act on behalf of a user.
* The On Behalf grant is only supported for access tokens. It does not work
* with any other type of token, including refresh tokens.
*/
export default class OnBehalfGrantTokenProvider implements TokenProvider {
private readonly _endpointProvider;
private readonly _clientId;
private readonly _clientSecret;
private readonly _accessToken;
private readonly _httpClient;
private _scopes;
private _refreshableTokenProvider?;
/**
* Public constructor for OnBehalfGrantTokenProvider class
*
* @param endpointProvider - An endpoint provider that provides the URL for the Trimble Identity token endpoints.
* It can be be OpenIdEndpointProvider/FixedEndpointProvider
* @param clientId - The client id for the calling application
* @param clientSecret - The client secret for the calling application
* @param accessToken - The access token that this application wishes to act on behalf of when calling another API
*/
constructor(endpointProvider: EndpointProvider, clientId: string, clientSecret: string, accessToken: string);
/**
* Fluent extension to add scopes
*
* @param scopes - The scopes to add to the token provider
* @returns This token provider instance for method chaining
*/
WithScopes(scopes: string[]): OnBehalfGrantTokenProvider;
/**
* Retrieves an access token for the application
*
* @returns A Promise that resolves to the value of the access token on completion
* @throws When a token endpoint is not provided by the endpoint provider
* @throws When a call to the token endpoint fails
*/
RetrieveToken(): Promise<string>;
private _retrieveToken;
}