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

Update the framename to reflect authority and scopes #1267

Merged
merged 8 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 5 additions & 3 deletions lib/msal-core/src/UserAgentApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Constants,
TemporaryCacheKeys,
PersistentCacheKeys,
ErrorCacheKeys,
FramePrefix
} from "./utils/Constants";

// default authority
Expand Down Expand Up @@ -1286,9 +1287,9 @@ export class UserAgentApplication {
*/
private renewToken(scopes: Array<string>, resolve: Function, reject: Function, account: Account, serverAuthenticationRequest: ServerRequestParameters): void {
const scope = scopes.join(" ").toLowerCase();
this.logger.verbose("renewToken is called for scope:" + scope);
this.logger.verbose("renewToken is called for scope: " + scope + " authority: " + serverAuthenticationRequest.authority);

const frameName = `msalRenewFrame${scope}`;
const frameName = WindowUtils.generateFrameName(FramePrefix.TOKEN_FRAME, scopes, serverAuthenticationRequest.authority);
const frameHandle = WindowUtils.addHiddenIFrame(frameName, this.logger);

this.updateCacheEntries(serverAuthenticationRequest, account);
Expand All @@ -1312,7 +1313,8 @@ export class UserAgentApplication {
*/
private renewIdToken(scopes: Array<string>, resolve: Function, reject: Function, account: Account, serverAuthenticationRequest: ServerRequestParameters): void {
this.logger.info("renewidToken is called");
const frameName = "msalIdTokenFrame";

const frameName = WindowUtils.generateFrameName(FramePrefix.ID_TOKEN_FRAME, scopes, serverAuthenticationRequest.authority);
const frameHandle = WindowUtils.addHiddenIFrame(frameName, this.logger);

this.updateCacheEntries(serverAuthenticationRequest, account);
Expand Down
12 changes: 10 additions & 2 deletions lib/msal-core/src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ export const PromptState = {
LOGIN: "login",
SELECT_ACCOUNT: "select_account",
CONSENT: "consent",
NONE: "none",
NONE: "none"
};

/**
* Frame name prefixes for the hidden iframe created in silent frames
*/
export const FramePrefix = {
ID_TOKEN_FRAME: "msalIdTokenFrame",
TOKEN_FRAME: "msalRenewFrame"
};

/**
* MSAL JS Library Version
*/
export function libraryVersion(): string {
return "1.2.1";
}
};
10 changes: 10 additions & 0 deletions lib/msal-core/src/utils/WindowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class WindowUtils {
return !!(window.opener && window.opener !== window);
}

/**
* @hidden
* @param prefix
* @param scopes
* @param authority
*/
static generateFrameName(prefix: string, scopes: string[], authority: string): string {
return `${prefix}${Constants.resourceDelimiter}${scopes.join(" ").toLowerCase()}${Constants.resourceDelimiter}${authority}`;
}

/**
* @hidden
* Monitors a window until it loads a url with a hash
Expand Down
15 changes: 15 additions & 0 deletions lib/msal-core/test/utils/WindowUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { WindowUtils } from "../../src/utils/WindowUtils";
import { FramePrefix } from "../../src/utils/Constants";
import { TEST_CONFIG } from "../TestConstants";
import { ClientAuthError } from "../../src/error/ClientAuthError";

describe("WindowUtils", () => {
Expand Down Expand Up @@ -70,4 +72,17 @@ describe("WindowUtils", () => {
}, 500);
});
});

describe("generateFrameName", () => {
it("test idToken frame name created", () => {
const scopes = ["s1", "s2", "s3"];
const authority = TEST_CONFIG.validAuthority;

const idTokenFrameName = WindowUtils.generateFrameName(FramePrefix.ID_TOKEN_FRAME, scopes, authority);
const tokenFrameName = WindowUtils.generateFrameName(FramePrefix.TOKEN_FRAME, scopes, authority);

expect(idTokenFrameName).to.equal(`${FramePrefix.ID_TOKEN_FRAME}|s1 s2 s3|${TEST_CONFIG.validAuthority}`);
expect(tokenFrameName).to.equal(`${FramePrefix.TOKEN_FRAME}|s1 s2 s3|${TEST_CONFIG.validAuthority}`);
});
});
});