botbook/node_modules/@azure/msal-browser/dist/interaction_client/SilentRefreshClient.mjs

60 lines
3.2 KiB
JavaScript
Raw Normal View History

2024-09-04 13:13:15 -03:00
/*! @azure/msal-browser v3.23.0 2024-09-03 */
'use strict';
import { StandardInteractionClient } from './StandardInteractionClient.mjs';
import { PerformanceEvents, invokeAsync, RefreshTokenClient } from '@azure/msal-common';
import { ApiId } from '../utils/BrowserConstants.mjs';
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
import { initializeBaseRequest } from '../request/RequestHelpers.mjs';
import { silentLogoutUnsupported } from '../error/BrowserAuthErrorCodes.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class SilentRefreshClient extends StandardInteractionClient {
/**
* Exchanges the refresh token for new tokens
* @param request
*/
async acquireToken(request) {
this.performanceClient.addQueueMeasurement(PerformanceEvents.SilentRefreshClientAcquireToken, request.correlationId);
const baseRequest = await invokeAsync(initializeBaseRequest, PerformanceEvents.InitializeBaseRequest, this.logger, this.performanceClient, request.correlationId)(request, this.config, this.performanceClient, this.logger);
const silentRequest = {
...request,
...baseRequest,
};
if (request.redirectUri) {
// Make sure any passed redirectUri is converted to an absolute URL - redirectUri is not a required parameter for refresh token redemption so only include if explicitly provided
silentRequest.redirectUri = this.getRedirectUri(request.redirectUri);
}
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);
const refreshTokenClient = await this.createRefreshTokenClient(serverTelemetryManager, silentRequest.authority, silentRequest.azureCloudOptions, silentRequest.account);
// Send request to renew token. Auth module will throw errors if token cannot be renewed.
return invokeAsync(refreshTokenClient.acquireTokenByRefreshToken.bind(refreshTokenClient), PerformanceEvents.RefreshTokenClientAcquireTokenByRefreshToken, this.logger, this.performanceClient, request.correlationId)(silentRequest).catch((e) => {
e.setCorrelationId(this.correlationId);
serverTelemetryManager.cacheFailedRequest(e);
throw e;
});
}
/**
* Currently Unsupported
*/
logout() {
// Synchronous so we must reject
return Promise.reject(createBrowserAuthError(silentLogoutUnsupported));
}
/**
* Creates a Refresh Client with the given authority, or the default authority.
* @param serverTelemetryManager
* @param authorityUrl
*/
async createRefreshTokenClient(serverTelemetryManager, authorityUrl, azureCloudOptions, account) {
// Create auth module.
const clientConfig = await invokeAsync(this.getClientConfiguration.bind(this), PerformanceEvents.StandardInteractionClientGetClientConfiguration, this.logger, this.performanceClient, this.correlationId)(serverTelemetryManager, authorityUrl, azureCloudOptions, account);
return new RefreshTokenClient(clientConfig, this.performanceClient);
}
}
export { SilentRefreshClient };
//# sourceMappingURL=SilentRefreshClient.mjs.map