diff --git a/.changeset/chatty-gifts-fry.md b/.changeset/chatty-gifts-fry.md new file mode 100644 index 0000000000..25f0a70bd9 --- /dev/null +++ b/.changeset/chatty-gifts-fry.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +Replaces the usage of `got` with `node-fetch` in the `getUserPhoto` method of the Microsoft provider diff --git a/plugins/auth-backend/package.json b/plugins/auth-backend/package.json index c7d208eef2..5a7769c0fb 100644 --- a/plugins/auth-backend/package.json +++ b/plugins/auth-backend/package.json @@ -46,7 +46,6 @@ "express-promise-router": "^4.1.0", "express-session": "^1.17.1", "fs-extra": "9.1.0", - "got": "^11.5.2", "helmet": "^4.0.0", "jose": "^1.27.1", "jwt-decode": "^3.1.0", diff --git a/plugins/auth-backend/src/providers/microsoft/provider.ts b/plugins/auth-backend/src/providers/microsoft/provider.ts index 2dc259fe74..66bb32cfdd 100644 --- a/plugins/auth-backend/src/providers/microsoft/provider.ts +++ b/plugins/auth-backend/src/providers/microsoft/provider.ts @@ -45,7 +45,7 @@ import { SignInResolver, } from '../types'; import { Logger } from 'winston'; -import got from 'got'; +import fetch from 'node-fetch'; type PrivateInfo = { refreshToken: string; @@ -173,19 +173,18 @@ export class MicrosoftAuthProvider implements OAuthHandlers { private getUserPhoto(accessToken: string): Promise { return new Promise(resolve => { - got - .get('https://graph.microsoft.com/v1.0/me/photos/48x48/$value', { - encoding: 'binary', - responseType: 'buffer', - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }) - .then(photoData => { - const photoURL = `data:image/jpeg;base64,${Buffer.from( - photoData.body, + fetch('https://graph.microsoft.com/v1.0/me/photos/48x48/$value', { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }) + .then(response => response.arrayBuffer()) + .then(arrayBuffer => { + console.log(Buffer.from(arrayBuffer).toString('utf-8')); + const imageUrl = `data:image/jpeg;base64,${Buffer.from( + arrayBuffer, ).toString('base64')}`; - resolve(photoURL); + resolve(imageUrl); }) .catch(error => { this.logger.warn(