From 2c234a893256470ff19b0ac81e9c3c61eb6c51b9 Mon Sep 17 00:00:00 2001 From: Heikki Hellgren Date: Mon, 20 Feb 2023 09:20:42 +0200 Subject: [PATCH] fix: restore support for custom MS graph API url relates to #16361 Signed-off-by: Heikki Hellgren --- .changeset/slow-suits-grab.md | 5 +++++ .../src/microsoftGraph/client.test.ts | 2 +- .../src/microsoftGraph/client.ts | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/slow-suits-grab.md diff --git a/.changeset/slow-suits-grab.md b/.changeset/slow-suits-grab.md new file mode 100644 index 0000000000..4a741cac6b --- /dev/null +++ b/.changeset/slow-suits-grab.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-msgraph': patch +--- + +properly support custom graph api URL diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts index f621b4d924..6d63537b54 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts @@ -53,7 +53,7 @@ describe('MicrosoftGraphClient', () => { expect(await response.json()).toEqual({ value: 'example' }); expect(tokenCredential.getToken).toHaveBeenCalledTimes(1); expect(tokenCredential.getToken).toHaveBeenCalledWith( - 'https://graph.microsoft.com/.default', + 'https://other.example.com/.default', ); }); diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts index c644e545d6..4acf7c726e 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts @@ -218,8 +218,9 @@ export class MicrosoftGraphClient { headers?: Record, ): Promise { // Make sure that we always have a valid access token (might be cached) + const urlObj = new URL(url); const token = await this.tokenCredential.getToken( - 'https://graph.microsoft.com/.default', + `${urlObj.protocol}//${urlObj.hostname}/.default`, ); if (!token) {