@backstage/plugin-auth-backend-module-microsoft-provider 0.1.14-next.2 → 0.1.15
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 +20 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @backstage/plugin-auth-backend-module-microsoft-provider
|
|
2
2
|
|
|
3
|
+
## 0.1.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/plugin-auth-node@0.4.15
|
|
9
|
+
- @backstage/backend-plugin-api@0.6.20
|
|
10
|
+
|
|
11
|
+
## 0.1.14
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 78a0b08: Internal refactor to handle `BackendFeature` contract change.
|
|
16
|
+
- 8efc6cf: Added support for the new shared `additionalScopes` configuration.
|
|
17
|
+
- d44a20a: Added additional plugin metadata to `package.json`.
|
|
18
|
+
- c187a9c: Minor internal type updates
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/backend-plugin-api@0.6.19
|
|
21
|
+
- @backstage/plugin-auth-node@0.4.14
|
|
22
|
+
|
|
3
23
|
## 0.1.14-next.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/strategy.ts","../src/authenticator.ts","../src/resolvers.ts","../src/module.ts","../src/deprecated.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 userProfile(\n accessToken: string,\n done: (err?: Error | null, 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?: Error | null, 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.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","/*\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 {\n createOAuthAuthenticator,\n PassportOAuthAuthenticatorHelper,\n PassportOAuthDoneCallback,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\nimport { ExtendedMicrosoftStrategy } from './strategy';\nimport { union } from 'lodash';\n\n/** @public */\nexport const microsoftAuthenticator = createOAuthAuthenticator({\n defaultProfileTransform:\n PassportOAuthAuthenticatorHelper.defaultProfileTransform,\n initialize({ callbackUrl, config }) {\n const clientId = config.getString('clientId');\n const clientSecret = config.getString('clientSecret');\n const tenantId = config.getString('tenantId');\n const domainHint = config.getOptionalString('domainHint');\n const scope = union(\n ['user.read'],\n config.getOptionalStringArray('additionalScopes'),\n );\n\n const helper = PassportOAuthAuthenticatorHelper.from(\n new ExtendedMicrosoftStrategy(\n {\n clientID: clientId,\n clientSecret: clientSecret,\n callbackURL: callbackUrl,\n tenant: tenantId,\n scope: scope,\n },\n (\n accessToken: string,\n refreshToken: string,\n params: any,\n fullProfile: PassportProfile,\n done: PassportOAuthDoneCallback,\n ) => {\n done(\n undefined,\n { fullProfile, params, accessToken },\n { refreshToken },\n );\n },\n ),\n );\n\n return {\n helper,\n domainHint,\n };\n },\n\n async start(input, ctx) {\n const options: Record<string, string> = {\n accessType: 'offline',\n };\n\n if (ctx.domainHint !== undefined) {\n options.domain_hint = ctx.domainHint;\n }\n\n return ctx.helper.start(input, options);\n },\n\n async authenticate(input, ctx) {\n return ctx.helper.authenticate(input);\n },\n\n async refresh(input, ctx) {\n return ctx.helper.refresh(input);\n },\n});\n","/*\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 {\n OAuthAuthenticatorResult,\n createSignInResolverFactory,\n PassportProfile,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\n\n/**\n * Available sign-in resolvers for the Microsoft auth provider.\n *\n * @public\n */\nexport namespace microsoftSignInResolvers {\n /**\n * Looks up the user by matching their Microsoft username to the entity name.\n */\n export const emailMatchingUserEntityAnnotation = createSignInResolverFactory({\n create() {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>,\n ctx,\n ) => {\n const { profile } = info;\n\n if (!profile.email) {\n throw new Error('Microsoft profile contained no email');\n }\n\n return ctx.signInWithCatalogUser({\n annotations: {\n 'microsoft.com/email': profile.email,\n },\n });\n };\n },\n });\n}\n","/*\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 */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createOAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { microsoftAuthenticator } from './authenticator';\nimport { microsoftSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleMicrosoftProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'microsoft-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'microsoft',\n factory: createOAuthProviderFactory({\n authenticator: microsoftAuthenticator,\n signInResolverFactories: {\n ...microsoftSignInResolvers,\n ...commonSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n","/*\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 { authModuleMicrosoftProvider as deprecatedAuthModuleMicrosoftProvider } from './module';\n\n/**\n * @public\n * @deprecated Use default import instead\n */\nexport const authModuleMicrosoftProvider =\n deprecatedAuthModuleMicrosoftProvider;\n"],"names":["MicrosoftStrategy","decodeJwt","fetch","createOAuthAuthenticator","PassportOAuthAuthenticatorHelper","union","microsoftSignInResolvers","createSignInResolverFactory","authModuleMicrosoftProvider","createBackendModule","authProvidersExtensionPoint","createOAuthProviderFactory","commonSignInResolvers","deprecatedAuthModuleMicrosoftProvider"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAM,kCAAkCA,0BAAkB,CAAA;AAAA,EAC/D,WAAA,CACE,aACA,IACM,EAAA;AACN,IAAI,IAAA,IAAA,CAAK,eAAgB,CAAA,WAAW,CAAG,EAAA;AACrC,MAAA,IAAA,CAAK,MAAM,KAAS,CAAA,CAAA,CAAA;AACpB,MAAA,OAAA;AAAA,KACF;AAEA,IAAM,KAAA,CAAA,WAAA;AAAA,MACJ,WAAA;AAAA,MAC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E,MAAS,GAAA;AACP,MAAO,OAAA,OACL,MACA,GACG,KAAA;AACH,QAAM,MAAA,EAAE,SAAY,GAAA,IAAA,CAAA;AAEpB,QAAI,IAAA,CAAC,QAAQ,KAAO,EAAA;AAClB,UAAM,MAAA,IAAI,MAAM,sCAAsC,CAAA,CAAA;AAAA,SACxD;AAEA,QAAA,OAAO,IAAI,qBAAsB,CAAA;AAAA,UAC/B,WAAa,EAAA;AAAA,YACX,uBAAuB,OAAQ,CAAA,KAAA;AAAA,WACjC;AAAA,SACD,CAAA,CAAA;AAAA,OACH,CAAA;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AAAA,CAvBc,EAAAD,gCAAA,KAAAA,gCAAA,GAAA,EAAA,CAAA,CAAA;;ACHV,MAAME,gCAA8BC,oCAAoB,CAAA;AAAA,EAC7D,QAAU,EAAA,MAAA;AAAA,EACV,QAAU,EAAA,oBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,SAAW,EAAAC,0CAAA;AAAA,OACb;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,SAAA,EAAa,EAAA;AACxB,QAAA,SAAA,CAAU,gBAAiB,CAAA;AAAA,UACzB,UAAY,EAAA,WAAA;AAAA,UACZ,SAASC,yCAA2B,CAAA;AAAA,YAClC,aAAe,EAAA,sBAAA;AAAA,YACf,uBAAyB,EAAA;AAAA,cACvB,GAAGL,gCAAA;AAAA,cACH,GAAGM,oCAAA;AAAA,aACL;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;ACzBM,MAAM,2BACX,GAAAC;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/strategy.ts","../src/authenticator.ts","../src/resolvers.ts","../src/module.ts","../src/deprecated.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 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.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","/*\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 {\n createOAuthAuthenticator,\n PassportOAuthAuthenticatorHelper,\n PassportOAuthDoneCallback,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\nimport { ExtendedMicrosoftStrategy } from './strategy';\nimport { union } from 'lodash';\n\n/** @public */\nexport const microsoftAuthenticator = createOAuthAuthenticator({\n defaultProfileTransform:\n PassportOAuthAuthenticatorHelper.defaultProfileTransform,\n initialize({ callbackUrl, config }) {\n const clientId = config.getString('clientId');\n const clientSecret = config.getString('clientSecret');\n const tenantId = config.getString('tenantId');\n const domainHint = config.getOptionalString('domainHint');\n const scope = union(\n ['user.read'],\n config.getOptionalStringArray('additionalScopes'),\n );\n\n const helper = PassportOAuthAuthenticatorHelper.from(\n new ExtendedMicrosoftStrategy(\n {\n clientID: clientId,\n clientSecret: clientSecret,\n callbackURL: callbackUrl,\n tenant: tenantId,\n scope: scope,\n },\n (\n accessToken: string,\n refreshToken: string,\n params: any,\n fullProfile: PassportProfile,\n done: PassportOAuthDoneCallback,\n ) => {\n done(\n undefined,\n { fullProfile, params, accessToken },\n { refreshToken },\n );\n },\n ),\n );\n\n return {\n helper,\n domainHint,\n };\n },\n\n async start(input, ctx) {\n const options: Record<string, string> = {\n accessType: 'offline',\n };\n\n if (ctx.domainHint !== undefined) {\n options.domain_hint = ctx.domainHint;\n }\n\n return ctx.helper.start(input, options);\n },\n\n async authenticate(input, ctx) {\n return ctx.helper.authenticate(input);\n },\n\n async refresh(input, ctx) {\n return ctx.helper.refresh(input);\n },\n});\n","/*\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 {\n OAuthAuthenticatorResult,\n createSignInResolverFactory,\n PassportProfile,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\n\n/**\n * Available sign-in resolvers for the Microsoft auth provider.\n *\n * @public\n */\nexport namespace microsoftSignInResolvers {\n /**\n * Looks up the user by matching their Microsoft username to the entity name.\n */\n export const emailMatchingUserEntityAnnotation = createSignInResolverFactory({\n create() {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>,\n ctx,\n ) => {\n const { profile } = info;\n\n if (!profile.email) {\n throw new Error('Microsoft profile contained no email');\n }\n\n return ctx.signInWithCatalogUser({\n annotations: {\n 'microsoft.com/email': profile.email,\n },\n });\n };\n },\n });\n}\n","/*\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 */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createOAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { microsoftAuthenticator } from './authenticator';\nimport { microsoftSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleMicrosoftProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'microsoft-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'microsoft',\n factory: createOAuthProviderFactory({\n authenticator: microsoftAuthenticator,\n signInResolverFactories: {\n ...microsoftSignInResolvers,\n ...commonSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n","/*\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 { authModuleMicrosoftProvider as deprecatedAuthModuleMicrosoftProvider } from './module';\n\n/**\n * @public\n * @deprecated Use default import instead\n */\nexport const authModuleMicrosoftProvider =\n deprecatedAuthModuleMicrosoftProvider;\n"],"names":["MicrosoftStrategy","decodeJwt","fetch","createOAuthAuthenticator","PassportOAuthAuthenticatorHelper","union","microsoftSignInResolvers","createSignInResolverFactory","authModuleMicrosoftProvider","createBackendModule","authProvidersExtensionPoint","createOAuthProviderFactory","commonSignInResolvers","deprecatedAuthModuleMicrosoftProvider"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAM,kCAAkCA,0BAAkB,CAAA;AAAA,EAC/D,WAAA,CACE,aACA,IACM,EAAA;AACN,IAAI,IAAA,IAAA,CAAK,eAAgB,CAAA,WAAW,CAAG,EA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;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare const microsoftAuthenticator: _backstage_plugin_auth_node.OAuthAuthentic
|
|
|
9
9
|
}, PassportProfile>;
|
|
10
10
|
|
|
11
11
|
/** @public */
|
|
12
|
-
declare const authModuleMicrosoftProvider$1:
|
|
12
|
+
declare const authModuleMicrosoftProvider$1: _backstage_backend_plugin_api.BackendFeatureCompat;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Available sign-in resolvers for the Microsoft auth provider.
|
|
@@ -27,6 +27,6 @@ declare namespace microsoftSignInResolvers {
|
|
|
27
27
|
* @public
|
|
28
28
|
* @deprecated Use default import instead
|
|
29
29
|
*/
|
|
30
|
-
declare const authModuleMicrosoftProvider:
|
|
30
|
+
declare const authModuleMicrosoftProvider: _backstage_backend_plugin_api.BackendFeatureCompat;
|
|
31
31
|
|
|
32
32
|
export { authModuleMicrosoftProvider, authModuleMicrosoftProvider$1 as default, microsoftAuthenticator, microsoftSignInResolvers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-auth-backend-module-microsoft-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "The microsoft-provider backend module for the auth plugin.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"test": "backstage-cli package test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
38
|
-
"@backstage/plugin-auth-node": "^0.4.
|
|
37
|
+
"@backstage/backend-plugin-api": "^0.6.20",
|
|
38
|
+
"@backstage/plugin-auth-node": "^0.4.15",
|
|
39
39
|
"express": "^4.18.2",
|
|
40
40
|
"jose": "^5.0.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"passport-microsoft": "^1.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@backstage/backend-defaults": "^0.3.
|
|
48
|
-
"@backstage/backend-test-utils": "^0.4.
|
|
49
|
-
"@backstage/cli": "^0.26.
|
|
47
|
+
"@backstage/backend-defaults": "^0.3.1",
|
|
48
|
+
"@backstage/backend-test-utils": "^0.4.1",
|
|
49
|
+
"@backstage/cli": "^0.26.8",
|
|
50
50
|
"@backstage/config": "^1.2.0",
|
|
51
|
-
"@backstage/plugin-auth-backend": "^0.22.
|
|
51
|
+
"@backstage/plugin-auth-backend": "^0.22.7",
|
|
52
52
|
"@types/passport-microsoft": "^1.0.0",
|
|
53
53
|
"msw": "^1.0.0",
|
|
54
54
|
"supertest": "^6.3.3"
|