@backstage/plugin-auth-backend-module-microsoft-provider 0.2.2 → 0.2.3-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @backstage/plugin-auth-backend-module-microsoft-provider
2
2
 
3
+ ## 0.2.3-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5c9cc05: Use native fetch instead of node-fetch
8
+ - Updated dependencies
9
+ - @backstage/plugin-auth-node@0.5.5-next.1
10
+ - @backstage/backend-plugin-api@1.1.0-next.1
11
+
12
+ ## 0.2.3-next.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @backstage/backend-plugin-api@1.0.3-next.0
18
+ - @backstage/plugin-auth-node@0.5.5-next.0
19
+
3
20
  ## 0.2.2
4
21
 
5
22
  ### Patch Changes
@@ -1,13 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var jose = require('jose');
4
- var fetch = require('node-fetch');
5
4
  var passportMicrosoft = require('passport-microsoft');
6
5
 
7
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
-
9
- var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
10
-
11
6
  class ExtendedMicrosoftStrategy extends passportMicrosoft.Strategy {
12
7
  shouldSkipUserProfile = false;
13
8
  setSkipUserProfile(shouldSkipUserProfile) {
@@ -57,7 +52,7 @@ class ExtendedMicrosoftStrategy extends passportMicrosoft.Strategy {
57
52
  }
58
53
  async getCurrentUserPhoto(accessToken, size) {
59
54
  try {
60
- const res = await fetch__default.default(
55
+ const res = await fetch(
61
56
  `https://graph.microsoft.com/v1.0/me/photos/${size}/$value`,
62
57
  {
63
58
  headers: {
@@ -65,8 +60,8 @@ class ExtendedMicrosoftStrategy extends passportMicrosoft.Strategy {
65
60
  }
66
61
  }
67
62
  );
68
- const data = await res.buffer();
69
- return `data:image/jpeg;base64,${data.toString("base64")}`;
63
+ const data = await res.arrayBuffer();
64
+ return `data:image/jpeg;base64,${Buffer.from(data).toString("base64")}`;
70
65
  } catch (error) {
71
66
  return void 0;
72
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.cjs.js","sources":["../src/strategy.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PassportProfile } from '@backstage/plugin-auth-node';\nimport { decodeJwt } from 'jose';\nimport fetch from 'node-fetch';\nimport { Strategy as MicrosoftStrategy } from 'passport-microsoft';\n\nexport class ExtendedMicrosoftStrategy extends MicrosoftStrategy {\n private shouldSkipUserProfile = false;\n\n public setSkipUserProfile(shouldSkipUserProfile: boolean): void {\n this.shouldSkipUserProfile = shouldSkipUserProfile;\n }\n\n userProfile(\n accessToken: string,\n done: (err?: unknown, profile?: PassportProfile) => void,\n ): void {\n if (this.skipUserProfile(accessToken)) {\n done(null, undefined);\n return;\n }\n\n super.userProfile(\n accessToken,\n (err?: unknown, profile?: PassportProfile) => {\n if (!profile || profile.photos) {\n done(err, profile);\n return;\n }\n\n this.getProfilePhotos(accessToken).then(photos => {\n profile.photos = photos;\n done(err, profile);\n });\n },\n );\n }\n\n private hasGraphReadScope(accessToken: string): boolean {\n const { aud, scp } = decodeJwt(accessToken);\n return (\n aud === '00000003-0000-0000-c000-000000000000' &&\n !!scp &&\n (scp as string)\n .split(' ')\n .map(s => s.toLocaleLowerCase('en-US'))\n .some(s =>\n [\n 'https://graph.microsoft.com/user.read',\n 'https://graph.microsoft.com/user.read.all',\n 'user.read',\n 'user.read.all',\n ].includes(s),\n )\n );\n }\n\n private skipUserProfile(accessToken: string): boolean {\n try {\n return this.shouldSkipUserProfile || !this.hasGraphReadScope(accessToken);\n } catch {\n // If there is any error with checking the scope\n // we fall back to not skipping the user profile\n // which may still result in an auth failure\n // e.g. due to a foreign scope.\n return false;\n }\n }\n\n private async getProfilePhotos(\n accessToken: string,\n ): Promise<Array<{ value: string }> | undefined> {\n return this.getCurrentUserPhoto(accessToken, '96x96').then(photo =>\n photo ? [{ value: photo }] : undefined,\n );\n }\n\n private async getCurrentUserPhoto(\n accessToken: string,\n size: string,\n ): Promise<string | undefined> {\n try {\n const res = await fetch(\n `https://graph.microsoft.com/v1.0/me/photos/${size}/$value`,\n {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n },\n );\n const data = await res.buffer();\n\n return `data:image/jpeg;base64,${data.toString('base64')}`;\n } catch (error) {\n return undefined;\n }\n }\n}\n"],"names":["MicrosoftStrategy","decodeJwt","fetch"],"mappings":";;;;;;;;;;AAqBO,MAAM,kCAAkCA,0BAAkB,CAAA;AAAA,EACvD,qBAAwB,GAAA,KAAA;AAAA,EAEzB,mBAAmB,qBAAsC,EAAA;AAC9D,IAAA,IAAA,CAAK,qBAAwB,GAAA,qBAAA;AAAA;AAC/B,EAEA,WAAA,CACE,aACA,IACM,EAAA;AACN,IAAI,IAAA,IAAA,CAAK,eAAgB,CAAA,WAAW,CAAG,EAAA;AACrC,MAAA,IAAA,CAAK,MAAM,KAAS,CAAA,CAAA;AACpB,MAAA;AAAA;AAGF,IAAM,KAAA,CAAA,WAAA;AAAA,MACJ,WAAA;AAAA,MACA,CAAC,KAAe,OAA8B,KAAA;AAC5C,QAAI,IAAA,CAAC,OAAW,IAAA,OAAA,CAAQ,MAAQ,EAAA;AAC9B,UAAA,IAAA,CAAK,KAAK,OAAO,CAAA;AACjB,UAAA;AAAA;AAGF,QAAA,IAAA,CAAK,gBAAiB,CAAA,WAAW,CAAE,CAAA,IAAA,CAAK,CAAU,MAAA,KAA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AM,MAAA,IAAA,GAAO,MAAM,GAAA,CAAI,MAAO,EAAA;AAE9B,MAAA,OAAO,CAA0B,uBAAA,EAAA,IAAA,CAAK,QAAS,CAAA,QAAQ,CAAC,CAAA,CAAA;AAAA,aACjD,KAAO,EAAA;AACd,MAAO,OAAA,KAAA,CAAA;AAAA;AACT;AAEJ;;;;"}
1
+ {"version":3,"file":"strategy.cjs.js","sources":["../src/strategy.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PassportProfile } from '@backstage/plugin-auth-node';\nimport { decodeJwt } from 'jose';\nimport { Strategy as MicrosoftStrategy } from 'passport-microsoft';\n\nexport class ExtendedMicrosoftStrategy extends MicrosoftStrategy {\n private shouldSkipUserProfile = false;\n\n public setSkipUserProfile(shouldSkipUserProfile: boolean): void {\n this.shouldSkipUserProfile = shouldSkipUserProfile;\n }\n\n userProfile(\n accessToken: string,\n done: (err?: unknown, profile?: PassportProfile) => void,\n ): void {\n if (this.skipUserProfile(accessToken)) {\n done(null, undefined);\n return;\n }\n\n super.userProfile(\n accessToken,\n (err?: unknown, profile?: PassportProfile) => {\n if (!profile || profile.photos) {\n done(err, profile);\n return;\n }\n\n this.getProfilePhotos(accessToken).then(photos => {\n profile.photos = photos;\n done(err, profile);\n });\n },\n );\n }\n\n private hasGraphReadScope(accessToken: string): boolean {\n const { aud, scp } = decodeJwt(accessToken);\n return (\n aud === '00000003-0000-0000-c000-000000000000' &&\n !!scp &&\n (scp as string)\n .split(' ')\n .map(s => s.toLocaleLowerCase('en-US'))\n .some(s =>\n [\n 'https://graph.microsoft.com/user.read',\n 'https://graph.microsoft.com/user.read.all',\n 'user.read',\n 'user.read.all',\n ].includes(s),\n )\n );\n }\n\n private skipUserProfile(accessToken: string): boolean {\n try {\n return this.shouldSkipUserProfile || !this.hasGraphReadScope(accessToken);\n } catch {\n // If there is any error with checking the scope\n // we fall back to not skipping the user profile\n // which may still result in an auth failure\n // e.g. due to a foreign scope.\n return false;\n }\n }\n\n private async getProfilePhotos(\n accessToken: string,\n ): Promise<Array<{ value: string }> | undefined> {\n return this.getCurrentUserPhoto(accessToken, '96x96').then(photo =>\n photo ? [{ value: photo }] : undefined,\n );\n }\n\n private async getCurrentUserPhoto(\n accessToken: string,\n size: string,\n ): Promise<string | undefined> {\n try {\n const res = await fetch(\n `https://graph.microsoft.com/v1.0/me/photos/${size}/$value`,\n {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n },\n );\n const data = await res.arrayBuffer();\n\n return `data:image/jpeg;base64,${Buffer.from(data).toString('base64')}`;\n } catch (error) {\n return undefined;\n }\n }\n}\n"],"names":["MicrosoftStrategy","decodeJwt"],"mappings":";;;;;AAoBO,MAAM,kCAAkCA,0BAAkB,CAAA;AAAA,EACvD,qBAAwB,GAAA,KAAA;AAAA,EAEzB,mBAAmB,qBAAsC,EAAA;AAC9D,IAAA,IAAA,CAAK,qBAAwB,GAAA,qBAAA;AAAA;AAC/B,EAEA,WAAA,CACE,aACA,IACM,EAAA;AACN,IAAI,IAAA,IAAA,CAAK,eAAgB,CAAA,WAAW,CAAG,EAAA;AACrC,MAAA,IAAA,CAAK,MAAM,KAAS,CAAA,CAAA;AACpB,MAAA;AAAA;AAGF,IAAM,KAAA,CAAA,WAAA;AAAA,MACJ,WAAA;AAAA,MACA,CAAC,KAAe,OAA8B,KAAA;AAC5C,QAAI,IAAA,CAAC,OAAW,IAAA,OAAA,CAAQ,MAAQ,EAAA;AAC9B,UAAA,IAAA,CAAK,KAAK,OAAO,CAAA;AACjB,UAAA;AAAA;AAGF,QAAA,IA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AA,YACP,aAAA,EAAe,UAAU,WAAW,CAAA;AAAA;AACtC;AACF,OACF;AACA,MAAM,MAAA,IAAA,GAAO,MAAM,GAAA,CAAI,WAAY,EAAA;AAEnC,MAAA,OAAO,0BAA0B,MAAO,CAAA,IAAA,CAAK,IAAI,CAAE,CAAA,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,aAC9D,KAAO,EAAA;AACd,MAAO,OAAA,KAAA,CAAA;AAAA;AACT;AAEJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-auth-backend-module-microsoft-provider",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-next.1",
4
4
  "description": "The microsoft-provider backend module for the auth plugin.",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -34,19 +34,18 @@
34
34
  "test": "backstage-cli package test"
35
35
  },
36
36
  "dependencies": {
37
- "@backstage/backend-plugin-api": "^1.0.2",
38
- "@backstage/plugin-auth-node": "^0.5.4",
37
+ "@backstage/backend-plugin-api": "1.1.0-next.1",
38
+ "@backstage/plugin-auth-node": "0.5.5-next.1",
39
39
  "express": "^4.18.2",
40
40
  "jose": "^5.0.0",
41
- "node-fetch": "^2.7.0",
42
41
  "passport-microsoft": "^1.0.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@backstage/backend-defaults": "^0.5.3",
46
- "@backstage/backend-test-utils": "^1.1.0",
47
- "@backstage/cli": "^0.29.0",
48
- "@backstage/config": "^1.3.0",
49
- "@backstage/plugin-auth-backend": "^0.24.0",
44
+ "@backstage/backend-defaults": "0.6.0-next.1",
45
+ "@backstage/backend-test-utils": "1.2.0-next.1",
46
+ "@backstage/cli": "0.29.3-next.1",
47
+ "@backstage/config": "1.3.0",
48
+ "@backstage/plugin-auth-backend": "0.24.1-next.1",
50
49
  "@types/passport-microsoft": "^1.0.0",
51
50
  "msw": "^1.0.0",
52
51
  "supertest": "^7.0.0"