@azure/msal-node
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -13,3 +13,3 @@ import { NodeStorage } from "./NodeStorage.js"; | ||
private cacheSnapshot; | ||
private readonly persistence; | ||
readonly persistence: ICachePlugin; | ||
private logger; | ||
@@ -35,2 +35,6 @@ constructor(storage: NodeStorage, logger: Logger, cachePlugin?: ICachePlugin); | ||
/** | ||
* Gets cache snapshot in CacheKVStore format | ||
*/ | ||
getCacheSnapshot(): CacheKVStore; | ||
/** | ||
* API that retrieves all accounts currently in cache to the user | ||
@@ -59,2 +63,6 @@ */ | ||
/** | ||
* Overwrites in-memory cache with persistent cache | ||
*/ | ||
overwriteCache(): Promise<void>; | ||
/** | ||
* Called when the cache has changed state. | ||
@@ -61,0 +69,0 @@ */ |
@@ -80,2 +80,3 @@ import { ClientConfiguration, AuthenticationResult, BaseAuthRequest, Logger, ServerTelemetryManager, AzureRegionConfiguration, AzureCloudOptions, AuthorizationCodePayload, ClientAssertionCallback } from "@azure/msal-common/node"; | ||
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>; | ||
private acquireCachedTokenSilent; | ||
/** | ||
@@ -82,0 +83,0 @@ * Acquires tokens with password grant by exchanging client applications username and password for credentials |
export declare const name = "@azure/msal-node"; | ||
export declare const version = "3.1.0"; | ||
export declare const version = "3.2.0"; | ||
//# sourceMappingURL=packageMetadata.d.ts.map |
@@ -13,3 +13,3 @@ import { NodeStorage } from "./NodeStorage.js"; | ||
private cacheSnapshot; | ||
private readonly persistence; | ||
readonly persistence: ICachePlugin; | ||
private logger; | ||
@@ -35,2 +35,6 @@ constructor(storage: NodeStorage, logger: Logger, cachePlugin?: ICachePlugin); | ||
/** | ||
* Gets cache snapshot in CacheKVStore format | ||
*/ | ||
getCacheSnapshot(): CacheKVStore; | ||
/** | ||
* API that retrieves all accounts currently in cache to the user | ||
@@ -59,2 +63,6 @@ */ | ||
/** | ||
* Overwrites in-memory cache with persistent cache | ||
*/ | ||
overwriteCache(): Promise<void>; | ||
/** | ||
* Called when the cache has changed state. | ||
@@ -61,0 +69,0 @@ */ |
@@ -80,2 +80,3 @@ import { ClientConfiguration, AuthenticationResult, BaseAuthRequest, Logger, ServerTelemetryManager, AzureRegionConfiguration, AzureCloudOptions, AuthorizationCodePayload, ClientAssertionCallback } from "@azure/msal-common/node"; | ||
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>; | ||
private acquireCachedTokenSilent; | ||
/** | ||
@@ -82,0 +83,0 @@ * Acquires tokens with password grant by exchanging client applications username and password for credentials |
export declare const name = "@azure/msal-node"; | ||
export declare const version = "3.1.0"; | ||
export declare const version = "3.2.0"; | ||
//# sourceMappingURL=packageMetadata.d.ts.map |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@azure/msal-node", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"author": { | ||
@@ -85,3 +85,3 @@ "name": "Microsoft", | ||
"dependencies": { | ||
"@azure/msal-common": "15.0.2", | ||
"@azure/msal-common": "15.1.0", | ||
"jsonwebtoken": "^9.0.0", | ||
@@ -88,0 +88,0 @@ "uuid": "^8.3.0" |
@@ -45,3 +45,3 @@ /* | ||
private cacheSnapshot: string; | ||
private readonly persistence: ICachePlugin; | ||
public readonly persistence: ICachePlugin; | ||
private logger: Logger; | ||
@@ -121,2 +121,12 @@ | ||
/** | ||
* Gets cache snapshot in CacheKVStore format | ||
*/ | ||
getCacheSnapshot(): CacheKVStore { | ||
const deserializedPersistentStorage = NodeStorage.generateInMemoryCache( | ||
this.cacheSnapshot | ||
); | ||
return this.storage.inMemoryCacheToCache(deserializedPersistentStorage); | ||
} | ||
/** | ||
* API that retrieves all accounts currently in cache to the user | ||
@@ -205,2 +215,21 @@ */ | ||
/** | ||
* Overwrites in-memory cache with persistent cache | ||
*/ | ||
async overwriteCache(): Promise<void> { | ||
if (!this.persistence) { | ||
this.logger.info( | ||
"No persistence layer specified, cache cannot be overwritten" | ||
); | ||
return; | ||
} | ||
this.logger.info("Overwriting in-memory cache with persistent cache"); | ||
this.storage.clear(); | ||
const cacheContext = new TokenCacheContext(this, false); | ||
await this.persistence.beforeCacheAccess(cacheContext); | ||
const cacheSnapshot = this.getCacheSnapshot(); | ||
this.storage.setCache(cacheSnapshot); | ||
await this.persistence.afterCacheAccess(cacheContext); | ||
} | ||
/** | ||
* Called when the cache has changed state. | ||
@@ -207,0 +236,0 @@ */ |
@@ -39,2 +39,4 @@ /* | ||
ClientAssertionCallback, | ||
CacheOutcome, | ||
ClientAuthError, | ||
} from "@azure/msal-common/node"; | ||
@@ -283,4 +285,5 @@ import { | ||
); | ||
try { | ||
const silentFlowClientConfig = | ||
const clientConfiguration = | ||
await this.buildOauthClientConfiguration( | ||
@@ -292,7 +295,5 @@ validRequest.authority, | ||
undefined, | ||
request.azureCloudOptions | ||
validRequest.azureCloudOptions | ||
); | ||
const silentFlowClient = new SilentFlowClient( | ||
silentFlowClientConfig | ||
); | ||
const silentFlowClient = new SilentFlowClient(clientConfiguration); | ||
this.logger.verbose( | ||
@@ -302,12 +303,69 @@ "Silent flow client created", | ||
); | ||
return await silentFlowClient.acquireToken(validRequest); | ||
} catch (e) { | ||
if (e instanceof AuthError) { | ||
e.setCorrelationId(validRequest.correlationId); | ||
try { | ||
// always overwrite the in-memory cache with the persistence cache (if it exists) before a cache lookup | ||
await this.tokenCache.overwriteCache(); | ||
return await this.acquireCachedTokenSilent( | ||
validRequest, | ||
silentFlowClient, | ||
clientConfiguration | ||
); | ||
} catch (error) { | ||
if ( | ||
error instanceof ClientAuthError && | ||
error.errorCode === | ||
ClientAuthErrorCodes.tokenRefreshRequired | ||
) { | ||
const refreshTokenClient = new RefreshTokenClient( | ||
clientConfiguration | ||
); | ||
return refreshTokenClient.acquireTokenByRefreshToken( | ||
validRequest | ||
); | ||
} | ||
throw error; | ||
} | ||
serverTelemetryManager.cacheFailedRequest(e as AuthError); | ||
throw e; | ||
} catch (error) { | ||
if (error instanceof AuthError) { | ||
error.setCorrelationId(validRequest.correlationId); | ||
} | ||
serverTelemetryManager.cacheFailedRequest(error); | ||
throw error; | ||
} | ||
} | ||
private async acquireCachedTokenSilent( | ||
validRequest: CommonSilentFlowRequest, | ||
silentFlowClient: SilentFlowClient, | ||
clientConfiguration: ClientConfiguration | ||
): Promise<AuthenticationResult> { | ||
const [authResponse, cacheOutcome] = | ||
await silentFlowClient.acquireCachedToken({ | ||
...validRequest, | ||
scopes: validRequest.scopes?.length | ||
? validRequest.scopes | ||
: [...OIDC_DEFAULT_SCOPES], | ||
}); | ||
if (cacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) { | ||
this.logger.info( | ||
"ClientApplication:acquireCachedTokenSilent - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed." | ||
); | ||
// refresh the access token in the background | ||
const refreshTokenClient = new RefreshTokenClient( | ||
clientConfiguration | ||
); | ||
try { | ||
await refreshTokenClient.acquireTokenByRefreshToken( | ||
validRequest | ||
); | ||
} catch { | ||
// do nothing, this is running in the background and no action is to be taken upon success or failure | ||
} | ||
} | ||
// return the cached token | ||
return authResponse; | ||
} | ||
/** | ||
@@ -314,0 +372,0 @@ * Acquires tokens with password grant by exchanging client applications username and password for credentials |
/* eslint-disable header/header */ | ||
export const name = "@azure/msal-node"; | ||
export const version = "3.1.0"; | ||
export const version = "3.2.0"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2305298
29638
+ Added@azure/msal-common@15.1.0(transitive)
- Removed@azure/msal-common@15.0.2(transitive)
Updated@azure/msal-common@15.1.0