From 02b96f48b13b72dc96af1e31e33bdfec3b960974 Mon Sep 17 00:00:00 2001 From: Sameera Gajjarapu Date: Thu, 20 Apr 2023 16:38:16 -0700 Subject: [PATCH 1/2] fix a bug in CIAM authority support --- lib/msal-common/src/authority/Authority.ts | 2 +- lib/msal-common/test/authority/AuthorityFactory.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/msal-common/src/authority/Authority.ts b/lib/msal-common/src/authority/Authority.ts index 3fbf34bc0c..7daa2bcf1e 100644 --- a/lib/msal-common/src/authority/Authority.ts +++ b/lib/msal-common/src/authority/Authority.ts @@ -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(); diff --git a/lib/msal-common/test/authority/AuthorityFactory.spec.ts b/lib/msal-common/test/authority/AuthorityFactory.spec.ts index 4f50f4cf45..5083b0f666 100644 --- a/lib/msal-common/test/authority/AuthorityFactory.spec.ts +++ b/lib/msal-common/test/authority/AuthorityFactory.spec.ts @@ -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); From 6026c0cc271bacc046bd38ecfa6bb01d334ba8f2 Mon Sep 17 00:00:00 2001 From: Sameera Gajjarapu Date: Thu, 20 Apr 2023 16:47:20 -0700 Subject: [PATCH 2/2] Change files --- ...e-msal-common-c26c7676-d0d7-4113-877a-e56e36fb73eb.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@azure-msal-common-c26c7676-d0d7-4113-877a-e56e36fb73eb.json diff --git a/change/@azure-msal-common-c26c7676-d0d7-4113-877a-e56e36fb73eb.json b/change/@azure-msal-common-c26c7676-d0d7-4113-877a-e56e36fb73eb.json new file mode 100644 index 0000000000..5de66b6a60 --- /dev/null +++ b/change/@azure-msal-common-c26c7676-d0d7-4113-877a-e56e36fb73eb.json @@ -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" +}