@sap-cloud-sdk/connectivity
Version:
SAP Cloud SDK for JavaScript connectivity
28 lines (27 loc) • 1.68 kB
TypeScript
import type { Service } from './environment-accessor';
import type { CachingOptions } from './cache';
import type { JwtPayload } from './jsonwebtoken-type';
/**
* Returns an access token that can be used to call the given service. The token is fetched via a client credentials grant with the credentials of the given service.
* If multiple instances of the provided service exist, the first instance will be selected.
* When a JWT is passed, the tenant of the JWT will be used when performing the grant.
* When no JWT is passed, the grant will be performed using the provider tenant.
*
* Throws an error if there is no instance of the given service type or the XSUAA service, or if the request to the XSUAA service fails.
* @param service - The type of the service or an instance of {@link Service}.
* @param options - Options to influence caching behavior (see {@link CachingOptions}) and a JWT. By default, caching and usage of a circuit breaker are enabled.
* @returns Access token.
*/
export declare function serviceToken(service: string | Service, options?: CachingOptions & {
jwt?: string | JwtPayload;
}): Promise<string>;
/**
* Returns a JWT bearer token that can be used to call the given service.
* The token is fetched via a JWT bearer token grant using the user token + client credentials.
*
* Throws an error if there is no instance of the given service type.
* @param jwt - The JWT of the user for whom the access token should be fetched.
* @param service - The type of the service or an instance of {@link Service}.
* @returns A JWT bearer token.
*/
export declare function jwtBearerToken(jwt: string, service: string | Service): Promise<string>;