Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for forceRefresh and set cache default policy for NAA flows #7406

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add support for forceRefresh and set default cache policy in NAA flows",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
12 changes: 12 additions & 0 deletions lib/msal-browser/src/controllers/NestedAppAuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,20 @@ export class NestedAppAuthController implements IController {
return null;
}

// if the request has forceRefresh, we cannot look up in the cache
if (request.forceRefresh) {
this.logger.verbose(
"forceRefresh is set to true, skipping cache lookup"
);
return null;
}

// respect cache lookup policy
let result: AuthenticationResult | null = null;
if (!request.cacheLookupPolicy) {
request.cacheLookupPolicy = CacheLookupPolicy.Default;
}

switch (request.cacheLookupPolicy) {
case CacheLookupPolicy.Default:
case CacheLookupPolicy.AccessToken:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe("NestedAppAuthController.ts Class Unit Tests", () => {
);
});

it("acquireTokenSilent calls acquireTokenFromCach with no cache policy set", async () => {
it("acquireTokenSilent calls acquireTokenFromCache with no cache policy set", async () => {
jest.spyOn(
NestedAppAuthController.prototype as any,
"acquireTokenFromCache"
Expand Down Expand Up @@ -228,6 +228,28 @@ describe("NestedAppAuthController.ts Class Unit Tests", () => {
expect(response.accessToken).toEqual(testResponse.accessToken);
});

it("acquireTokenSilent ignores cache if forceRefresh is on", async () => {
mockBridge.addAuthResultResponse("GetToken", SILENT_TOKEN_RESPONSE);

const testRequest = {
scopes: [NAA_SCOPE],
account: testAccount,
forceRefresh: true,
correlationId: NAA_CORRELATION_ID,
};

const testTokenResponse = nestedAppAuthAdapter.fromNaaTokenResponse(
nestedAppAuthAdapter.toNaaTokenRequest(testRequest),
SILENT_TOKEN_RESPONSE,
0
);

const response = await pca.acquireTokenSilent(testRequest);

expect(response?.idToken).not.toBeNull();
expect(response.accessToken).toEqual(testTokenResponse.accessToken);
});

it("acquireTokenSilent sends the request to bridge if cache misses", async () => {
mockBridge.addAuthResultResponse("GetToken", SILENT_TOKEN_RESPONSE);
jest.spyOn(
Expand Down
Loading