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" +} 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);