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

Support missing slash in CIAM authority support #5917

Merged
merged 2 commits into from
Apr 22, 2023
Merged
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": "Fix bugs in CIAM Authority Support (#5917)",
"packageName": "@azure/msal-common",
"email": "sameera.gajjarapu@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion lib/msal-common/src/authority/Authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export class Authority {
* @param authority
*/
static transformCIAMAuthority(authority: string): string {
let ciamAuthority = authority;
let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : `${authority}${Constants.FORWARD_SLASH}`;
const authorityUrl = new UrlString(authority);
const authorityUrlComponents = authorityUrl.getUrlComponents();

Expand Down
9 changes: 9 additions & 0 deletions lib/msal-common/test/authority/AuthorityFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ describe("AuthorityFactory.ts Class Unit Tests", () => {
expect(resolveEndpointsStub).toHaveBeenCalledTimes(1);
});

it("createDiscoveredInstance transforms CIAM authority when trailing slash is missing", async () => {
const resolveEndpointsStub = jest.spyOn(Authority.prototype, "resolveEndpointsAsync").mockResolvedValue();
const authorityInstance = await AuthorityFactory.createDiscoveredInstance("https://test.ciamlogin.com", networkInterface, mockStorage, authorityOptions, logger);
expect(authorityInstance.authorityType).toBe(AuthorityType.Ciam);
expect(authorityInstance.canonicalAuthority).toBe("https://test.ciamlogin.com/test.onmicrosoft.com/");
expect(authorityInstance instanceof Authority);
expect(resolveEndpointsStub).toHaveBeenCalledTimes(1);
});

it("createDiscoveredInstance does not transform when there is a PATH", async () => {
const resolveEndpointsStub = jest.spyOn(Authority.prototype, "resolveEndpointsAsync").mockResolvedValue();
const authorityInstance = await AuthorityFactory.createDiscoveredInstance("https://test.ciamlogin.com/tenant/", networkInterface, mockStorage, authorityOptions, logger);
Expand Down