@backstage/plugin-auth-backend-module-aws-alb-provider 0.2.0 → 0.2.1-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 +22 -0
- package/dist/authenticator.cjs.js +86 -0
- package/dist/authenticator.cjs.js.map +1 -0
- package/dist/helpers.cjs.js +97 -0
- package/dist/helpers.cjs.js.map +1 -0
- package/dist/index.cjs.js +9 -210
- package/dist/index.cjs.js.map +1 -1
- package/dist/module.cjs.js +33 -0
- package/dist/module.cjs.js.map +1 -0
- package/dist/resolvers.cjs.js +25 -0
- package/dist/resolvers.cjs.js.map +1 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @backstage/plugin-auth-backend-module-aws-alb-provider
|
|
2
2
|
|
|
3
|
+
## 0.2.1-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 217458a: Updated configuration schema to include the new `allowedDomains` option for the `emailLocalPartMatchingUserEntityName` sign-in resolver.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-auth-node@0.5.3-next.1
|
|
10
|
+
- @backstage/backend-plugin-api@1.0.1-next.1
|
|
11
|
+
- @backstage/errors@1.2.4
|
|
12
|
+
- @backstage/plugin-auth-backend@0.23.1-next.1
|
|
13
|
+
|
|
14
|
+
## 0.2.1-next.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 094eaa3: Remove references to in-repo backend-common
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/plugin-auth-backend@0.23.1-next.0
|
|
21
|
+
- @backstage/plugin-auth-node@0.5.3-next.0
|
|
22
|
+
- @backstage/backend-plugin-api@1.0.1-next.0
|
|
23
|
+
- @backstage/errors@1.2.4
|
|
24
|
+
|
|
3
25
|
## 0.2.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
var jose = require('jose');
|
|
5
|
+
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
6
|
+
var NodeCache = require('node-cache');
|
|
7
|
+
var helpers = require('./helpers.cjs.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var NodeCache__default = /*#__PURE__*/_interopDefaultCompat(NodeCache);
|
|
12
|
+
|
|
13
|
+
const ALB_JWT_HEADER = "x-amzn-oidc-data";
|
|
14
|
+
const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
|
|
15
|
+
const awsAlbAuthenticator = pluginAuthNode.createProxyAuthenticator({
|
|
16
|
+
defaultProfileTransform: async (result) => {
|
|
17
|
+
return {
|
|
18
|
+
profile: helpers.makeProfileInfo(result.fullProfile, result.accessToken)
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
initialize({ config }) {
|
|
22
|
+
const issuer = config.getString("issuer");
|
|
23
|
+
const signer = config.getOptionalString("signer");
|
|
24
|
+
const region = config.getString("region");
|
|
25
|
+
const keyCache = new NodeCache__default.default({ stdTTL: 3600 });
|
|
26
|
+
const getKey = helpers.provisionKeyCache(region, keyCache);
|
|
27
|
+
return { issuer, signer, getKey };
|
|
28
|
+
},
|
|
29
|
+
async authenticate({ req }, { issuer, signer, getKey }) {
|
|
30
|
+
const jwt = req.header(ALB_JWT_HEADER);
|
|
31
|
+
const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);
|
|
32
|
+
if (jwt === void 0) {
|
|
33
|
+
throw new errors.AuthenticationError(
|
|
34
|
+
`Missing ALB OIDC header: ${ALB_JWT_HEADER}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (accessToken === void 0) {
|
|
38
|
+
throw new errors.AuthenticationError(
|
|
39
|
+
`Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const verifyResult = await jose.jwtVerify(jwt, getKey);
|
|
44
|
+
const header = verifyResult.protectedHeader;
|
|
45
|
+
const claims = verifyResult.payload;
|
|
46
|
+
if (claims?.iss !== issuer) {
|
|
47
|
+
throw new errors.AuthenticationError("Issuer mismatch on JWT token");
|
|
48
|
+
} else if (signer && header?.signer !== signer) {
|
|
49
|
+
throw new errors.AuthenticationError("Signer mismatch on JWT token");
|
|
50
|
+
}
|
|
51
|
+
if (!claims.email) {
|
|
52
|
+
throw new errors.AuthenticationError(`Missing email in the JWT token`);
|
|
53
|
+
}
|
|
54
|
+
const fullProfile = {
|
|
55
|
+
provider: "unknown",
|
|
56
|
+
id: claims.sub,
|
|
57
|
+
displayName: claims.name,
|
|
58
|
+
username: claims.email.split("@")[0].toLowerCase(),
|
|
59
|
+
name: {
|
|
60
|
+
familyName: claims.family_name,
|
|
61
|
+
givenName: claims.given_name
|
|
62
|
+
},
|
|
63
|
+
emails: [{ value: claims.email.toLowerCase() }],
|
|
64
|
+
photos: [{ value: claims.picture }]
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
result: {
|
|
68
|
+
fullProfile,
|
|
69
|
+
accessToken,
|
|
70
|
+
expiresInSeconds: claims.exp
|
|
71
|
+
},
|
|
72
|
+
providerInfo: {
|
|
73
|
+
accessToken,
|
|
74
|
+
expiresInSeconds: claims.exp
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw new Error(`Exception occurred during JWT processing: ${e}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
exports.ALB_ACCESS_TOKEN_HEADER = ALB_ACCESS_TOKEN_HEADER;
|
|
84
|
+
exports.ALB_JWT_HEADER = ALB_JWT_HEADER;
|
|
85
|
+
exports.awsAlbAuthenticator = awsAlbAuthenticator;
|
|
86
|
+
//# sourceMappingURL=authenticator.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticator.cjs.js","sources":["../src/authenticator.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 { AuthenticationError } from '@backstage/errors';\nimport { AwsAlbClaims, AwsAlbProtectedHeader, AwsAlbResult } from './types';\nimport { jwtVerify } from 'jose';\nimport {\n createProxyAuthenticator,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\nimport NodeCache from 'node-cache';\nimport { makeProfileInfo, provisionKeyCache } from './helpers';\n\nexport const ALB_JWT_HEADER = 'x-amzn-oidc-data';\nexport const ALB_ACCESS_TOKEN_HEADER = 'x-amzn-oidc-accesstoken';\n\n/** @public */\nexport const awsAlbAuthenticator = createProxyAuthenticator({\n defaultProfileTransform: async (result: AwsAlbResult) => {\n return {\n profile: makeProfileInfo(result.fullProfile, result.accessToken),\n };\n },\n initialize({ config }) {\n const issuer = config.getString('issuer');\n const signer = config.getOptionalString('signer');\n const region = config.getString('region');\n const keyCache = new NodeCache({ stdTTL: 3600 });\n const getKey = provisionKeyCache(region, keyCache);\n return { issuer, signer, getKey };\n },\n async authenticate({ req }, { issuer, signer, getKey }) {\n const jwt = req.header(ALB_JWT_HEADER);\n const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);\n\n if (jwt === undefined) {\n throw new AuthenticationError(\n `Missing ALB OIDC header: ${ALB_JWT_HEADER}`,\n );\n }\n\n if (accessToken === undefined) {\n throw new AuthenticationError(\n `Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`,\n );\n }\n\n try {\n const verifyResult = await jwtVerify(jwt, getKey);\n const header = verifyResult.protectedHeader as AwsAlbProtectedHeader;\n const claims = verifyResult.payload as AwsAlbClaims;\n\n if (claims?.iss !== issuer) {\n throw new AuthenticationError('Issuer mismatch on JWT token');\n } else if (signer && header?.signer !== signer) {\n throw new AuthenticationError('Signer mismatch on JWT token');\n }\n\n if (!claims.email) {\n throw new AuthenticationError(`Missing email in the JWT token`);\n }\n\n const fullProfile: PassportProfile = {\n provider: 'unknown',\n id: claims.sub,\n displayName: claims.name,\n username: claims.email.split('@')[0].toLowerCase(),\n name: {\n familyName: claims.family_name,\n givenName: claims.given_name,\n },\n emails: [{ value: claims.email.toLowerCase() }],\n photos: [{ value: claims.picture }],\n };\n\n return {\n result: {\n fullProfile,\n accessToken: accessToken,\n expiresInSeconds: claims.exp,\n },\n providerInfo: {\n accessToken: accessToken,\n expiresInSeconds: claims.exp,\n },\n };\n } catch (e) {\n throw new Error(`Exception occurred during JWT processing: ${e}`);\n }\n },\n});\n"],"names":["createProxyAuthenticator","makeProfileInfo","NodeCache","provisionKeyCache","AuthenticationError","jwtVerify"],"mappings":";;;;;;;;;;;;AA0BO,MAAM,cAAiB,GAAA,mBAAA;AACvB,MAAM,uBAA0B,GAAA,0BAAA;AAGhC,MAAM,sBAAsBA,uCAAyB,CAAA;AAAA,EAC1D,uBAAA,EAAyB,OAAO,MAAyB,KAAA;AACvD,IAAO,OAAA;AAAA,MACL,OAAS,EAAAC,uBAAA,CAAgB,MAAO,CAAA,WAAA,EAAa,OAAO,WAAW,CAAA;AAAA,KACjE,CAAA;AAAA,GACF;AAAA,EACA,UAAA,CAAW,EAAE,MAAA,EAAU,EAAA;AACrB,IAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,QAAQ,CAAA,CAAA;AACxC,IAAM,MAAA,MAAA,GAAS,MAAO,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ch = require('node-fetch');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceCompat(e) {
|
|
11
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespaceCompat(crypto);
|
|
29
|
+
var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
30
|
+
|
|
31
|
+
const makeProfileInfo = (profile, idToken) => {
|
|
32
|
+
let email = void 0;
|
|
33
|
+
if (profile.emails && profile.emails.length > 0) {
|
|
34
|
+
const [firstEmail] = profile.emails;
|
|
35
|
+
email = firstEmail.value;
|
|
36
|
+
}
|
|
37
|
+
let picture = void 0;
|
|
38
|
+
if (profile.avatarUrl) {
|
|
39
|
+
picture = profile.avatarUrl;
|
|
40
|
+
} else if (profile.photos && profile.photos.length > 0) {
|
|
41
|
+
const [firstPhoto] = profile.photos;
|
|
42
|
+
picture = firstPhoto.value;
|
|
43
|
+
}
|
|
44
|
+
let displayName = profile.displayName ?? profile.username ?? profile.id;
|
|
45
|
+
if ((!email || !picture || !displayName) && idToken) {
|
|
46
|
+
try {
|
|
47
|
+
const decoded = jose.decodeJwt(idToken);
|
|
48
|
+
if (!email && decoded.email) {
|
|
49
|
+
email = decoded.email;
|
|
50
|
+
}
|
|
51
|
+
if (!picture && decoded.picture) {
|
|
52
|
+
picture = decoded.picture;
|
|
53
|
+
}
|
|
54
|
+
if (!displayName && decoded.name) {
|
|
55
|
+
displayName = decoded.name;
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new Error(`Failed to parse id token and get profile info, ${e}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
email,
|
|
63
|
+
picture,
|
|
64
|
+
displayName
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const getPublicKeyEndpoint = (region) => {
|
|
68
|
+
if (region.startsWith("us-gov")) {
|
|
69
|
+
return `https://s3-${encodeURIComponent(
|
|
70
|
+
region
|
|
71
|
+
)}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}`;
|
|
72
|
+
}
|
|
73
|
+
return `https://public-keys.auth.elb.${encodeURIComponent(
|
|
74
|
+
region
|
|
75
|
+
)}.amazonaws.com`;
|
|
76
|
+
};
|
|
77
|
+
const provisionKeyCache = (region, keyCache) => {
|
|
78
|
+
return async (header) => {
|
|
79
|
+
if (!header.kid) {
|
|
80
|
+
throw new errors.AuthenticationError("No key id was specified in header");
|
|
81
|
+
}
|
|
82
|
+
const optionalCacheKey = keyCache.get(header.kid);
|
|
83
|
+
if (optionalCacheKey) {
|
|
84
|
+
return crypto__namespace.createPublicKey(optionalCacheKey);
|
|
85
|
+
}
|
|
86
|
+
const keyText = await fetch__default.default(
|
|
87
|
+
`${getPublicKeyEndpoint(region)}/${encodeURIComponent(header.kid)}`
|
|
88
|
+
).then((response) => response.text());
|
|
89
|
+
const keyValue = crypto__namespace.createPublicKey(keyText);
|
|
90
|
+
keyCache.set(header.kid, keyValue.export({ format: "pem", type: "spki" }));
|
|
91
|
+
return keyValue;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.makeProfileInfo = makeProfileInfo;
|
|
96
|
+
exports.provisionKeyCache = provisionKeyCache;
|
|
97
|
+
//# sourceMappingURL=helpers.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs.js","sources":["../src/helpers.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 */\nimport { KeyObject } from 'crypto';\nimport * as crypto from 'crypto';\nimport { JWTHeaderParameters, decodeJwt } from 'jose';\nimport NodeCache from 'node-cache';\nimport fetch from 'node-fetch';\nimport { PassportProfile, ProfileInfo } from '@backstage/plugin-auth-node';\nimport { AuthenticationError } from '@backstage/errors';\n\nexport const makeProfileInfo = (\n profile: PassportProfile,\n idToken?: string,\n): ProfileInfo => {\n let email: string | undefined = undefined;\n if (profile.emails && profile.emails.length > 0) {\n const [firstEmail] = profile.emails;\n email = firstEmail.value;\n }\n\n let picture: string | undefined = undefined;\n if (profile.avatarUrl) {\n picture = profile.avatarUrl;\n } else if (profile.photos && profile.photos.length > 0) {\n const [firstPhoto] = profile.photos;\n picture = firstPhoto.value;\n }\n\n let displayName: string | undefined =\n profile.displayName ?? profile.username ?? profile.id;\n\n if ((!email || !picture || !displayName) && idToken) {\n try {\n const decoded: Record<string, string> = decodeJwt(idToken) as {\n email?: string;\n picture?: string;\n name?: string;\n };\n if (!email && decoded.email) {\n email = decoded.email;\n }\n if (!picture && decoded.picture) {\n picture = decoded.picture;\n }\n if (!displayName && decoded.name) {\n displayName = decoded.name;\n }\n } catch (e) {\n throw new Error(`Failed to parse id token and get profile info, ${e}`);\n }\n }\n\n return {\n email,\n picture,\n displayName,\n };\n};\n\nconst getPublicKeyEndpoint = (region: string) => {\n if (region.startsWith('us-gov')) {\n return `https://s3-${encodeURIComponent(\n region,\n )}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}`;\n }\n\n return `https://public-keys.auth.elb.${encodeURIComponent(\n region,\n )}.amazonaws.com`;\n};\n\nexport const provisionKeyCache = (region: string, keyCache: NodeCache) => {\n return async (header: JWTHeaderParameters): Promise<KeyObject> => {\n if (!header.kid) {\n throw new AuthenticationError('No key id was specified in header');\n }\n const optionalCacheKey = keyCache.get<KeyObject>(header.kid);\n if (optionalCacheKey) {\n return crypto.createPublicKey(optionalCacheKey);\n }\n\n const keyText: string = await fetch(\n `${getPublicKeyEndpoint(region)}/${encodeURIComponent(header.kid)}`,\n ).then(response => response.text());\n\n const keyValue = crypto.createPublicKey(keyText);\n keyCache.set(header.kid, keyValue.export({ format: 'pem', type: 'spki' }));\n return keyValue;\n };\n};\n"],"names":["decodeJwt","AuthenticationError","crypto","fetch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBa,MAAA,eAAA,GAAkB,CAC7B,OAAA,EACA,OACgB,KAAA;AAChB,EAAA,IAAI,KAA4B,GAAA,KAAA,CAAA,CAAA;AAChC,EAAA,IAAI,OAAQ,CAAA,MAAA,IAAU,OAAQ,CAAA,MAAA,CAAO,SAAS,CAAG,EAAA;AAC/C,IAAM,MAAA,CAAC,UAAU,CAAA,GAAI,OAAQ,CAAA,MAAA,CAAA;AAC7B,IAAA,KAAA,GAAQ,UAAW,CAAA,KAAA,CAAA;AAAA,GACrB;AAEA,EAAA,IAAI,OAA8B,GAAA,KAAA,CAAA,CAAA;AAClC,EAAA,IAAI,QAAQ,SAAW,EAAA;AACrB,IAAA,OAAA,GAAU,OAAQ,CAAA,SAAA,CAAA;AAAA,aACT,OAAQ,CAAA,MAAA,IAAU,OAAQ,CAAA,MAAA,CAAO,SAAS,CAAG,EAAA;AACtD,IAAM,MAAA,CAAC,UAAU,CAAA,GAA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AAA,EAAA,kBAAA;AAAA,IACrC,MAAA;AAAA,GACD,CAAA,cAAA,CAAA,CAAA;AACH,CAAA,CAAA;AAEa,MAAA,iBAAA,GAAoB,CAAC,MAAA,EAAgB,QAAwB,KAAA;AACxE,EAAA,OAAO,OAAO,MAAoD,KAAA;AAChE,IAAI,IAAA,CAAC,OAAO,GAAK,EAAA;AACf,MAAM,MAAA,IAAIC,2BAAoB,mCAAmC,CAAA,CAAA;AAAA,KACnE;AACA,IAAA,MAAM,gBAAmB,GAAA,QAAA,CAAS,GAAe,CAAA,MAAA,CAAO,GAAG,CAAA,CAAA;AAC3D,IAAA,IAAI,gBAAkB,EAAA;AACpB,MAAO,OAAAC,iBAAA,CAAO,gBAAgB,gBAAgB,CAAA,CAAA;AAAA,KAChD;AAEA,IAAA,MAAM,UAAkB,MAAMC,sBAAA;AAAA,MAC5B,CAAA,EAAG,qBAAqB,MAAM,CAAC,IAAI,kBAAmB,CAAA,MAAA,CAAO,GAAG,CAAC,CAAA,CAAA;AAAA,KACjE,CAAA,IAAA,CAAK,CAAY,QAAA,KAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AAElC,IAAM,MAAA,QAAA,GAAWD,iBAAO,CAAA,eAAA,CAAgB,OAAO,CAAA,CAAA;AAC/C,IAAS,QAAA,CAAA,GAAA,CAAI,MAAO,CAAA,GAAA,EAAK,QAAS,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,KAAO,EAAA,IAAA,EAAM,MAAO,EAAC,CAAC,CAAA,CAAA;AACzE,IAAO,OAAA,QAAA,CAAA;AAAA,GACT,CAAA;AACF;;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,218 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var NodeCache = require('node-cache');
|
|
9
|
-
var crypto = require('crypto');
|
|
10
|
-
var fetch = require('node-fetch');
|
|
11
|
-
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
5
|
+
var authenticator = require('./authenticator.cjs.js');
|
|
6
|
+
var module$1 = require('./module.cjs.js');
|
|
7
|
+
var resolvers = require('./resolvers.cjs.js');
|
|
12
8
|
|
|
13
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
14
9
|
|
|
15
|
-
function _interopNamespaceCompat(e) {
|
|
16
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
Object.keys(e).forEach(function (k) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () { return e[k]; }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
10
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (profile.emails && profile.emails.length > 0) {
|
|
40
|
-
const [firstEmail] = profile.emails;
|
|
41
|
-
email = firstEmail.value;
|
|
42
|
-
}
|
|
43
|
-
let picture = void 0;
|
|
44
|
-
if (profile.avatarUrl) {
|
|
45
|
-
picture = profile.avatarUrl;
|
|
46
|
-
} else if (profile.photos && profile.photos.length > 0) {
|
|
47
|
-
const [firstPhoto] = profile.photos;
|
|
48
|
-
picture = firstPhoto.value;
|
|
49
|
-
}
|
|
50
|
-
let displayName = profile.displayName ?? profile.username ?? profile.id;
|
|
51
|
-
if ((!email || !picture || !displayName) && idToken) {
|
|
52
|
-
try {
|
|
53
|
-
const decoded = jose.decodeJwt(idToken);
|
|
54
|
-
if (!email && decoded.email) {
|
|
55
|
-
email = decoded.email;
|
|
56
|
-
}
|
|
57
|
-
if (!picture && decoded.picture) {
|
|
58
|
-
picture = decoded.picture;
|
|
59
|
-
}
|
|
60
|
-
if (!displayName && decoded.name) {
|
|
61
|
-
displayName = decoded.name;
|
|
62
|
-
}
|
|
63
|
-
} catch (e) {
|
|
64
|
-
throw new Error(`Failed to parse id token and get profile info, ${e}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
email,
|
|
69
|
-
picture,
|
|
70
|
-
displayName
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
const getPublicKeyEndpoint = (region) => {
|
|
74
|
-
if (region.startsWith("us-gov")) {
|
|
75
|
-
return `https://s3-${encodeURIComponent(
|
|
76
|
-
region
|
|
77
|
-
)}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}`;
|
|
78
|
-
}
|
|
79
|
-
return `https://public-keys.auth.elb.${encodeURIComponent(
|
|
80
|
-
region
|
|
81
|
-
)}.amazonaws.com`;
|
|
82
|
-
};
|
|
83
|
-
const provisionKeyCache = (region, keyCache) => {
|
|
84
|
-
return async (header) => {
|
|
85
|
-
if (!header.kid) {
|
|
86
|
-
throw new errors.AuthenticationError("No key id was specified in header");
|
|
87
|
-
}
|
|
88
|
-
const optionalCacheKey = keyCache.get(header.kid);
|
|
89
|
-
if (optionalCacheKey) {
|
|
90
|
-
return crypto__namespace.createPublicKey(optionalCacheKey);
|
|
91
|
-
}
|
|
92
|
-
const keyText = await fetch__default.default(
|
|
93
|
-
`${getPublicKeyEndpoint(region)}/${encodeURIComponent(header.kid)}`
|
|
94
|
-
).then((response) => response.text());
|
|
95
|
-
const keyValue = crypto__namespace.createPublicKey(keyText);
|
|
96
|
-
keyCache.set(header.kid, keyValue.export({ format: "pem", type: "spki" }));
|
|
97
|
-
return keyValue;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const ALB_JWT_HEADER = "x-amzn-oidc-data";
|
|
102
|
-
const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
|
|
103
|
-
const awsAlbAuthenticator = pluginAuthNode.createProxyAuthenticator({
|
|
104
|
-
defaultProfileTransform: async (result) => {
|
|
105
|
-
return {
|
|
106
|
-
profile: makeProfileInfo(result.fullProfile, result.accessToken)
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
initialize({ config }) {
|
|
110
|
-
const issuer = config.getString("issuer");
|
|
111
|
-
const signer = config.getOptionalString("signer");
|
|
112
|
-
const region = config.getString("region");
|
|
113
|
-
const keyCache = new NodeCache__default.default({ stdTTL: 3600 });
|
|
114
|
-
const getKey = provisionKeyCache(region, keyCache);
|
|
115
|
-
return { issuer, signer, getKey };
|
|
116
|
-
},
|
|
117
|
-
async authenticate({ req }, { issuer, signer, getKey }) {
|
|
118
|
-
const jwt = req.header(ALB_JWT_HEADER);
|
|
119
|
-
const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);
|
|
120
|
-
if (jwt === void 0) {
|
|
121
|
-
throw new errors.AuthenticationError(
|
|
122
|
-
`Missing ALB OIDC header: ${ALB_JWT_HEADER}`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
if (accessToken === void 0) {
|
|
126
|
-
throw new errors.AuthenticationError(
|
|
127
|
-
`Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
const verifyResult = await jose.jwtVerify(jwt, getKey);
|
|
132
|
-
const header = verifyResult.protectedHeader;
|
|
133
|
-
const claims = verifyResult.payload;
|
|
134
|
-
if (claims?.iss !== issuer) {
|
|
135
|
-
throw new errors.AuthenticationError("Issuer mismatch on JWT token");
|
|
136
|
-
} else if (signer && header?.signer !== signer) {
|
|
137
|
-
throw new errors.AuthenticationError("Signer mismatch on JWT token");
|
|
138
|
-
}
|
|
139
|
-
if (!claims.email) {
|
|
140
|
-
throw new errors.AuthenticationError(`Missing email in the JWT token`);
|
|
141
|
-
}
|
|
142
|
-
const fullProfile = {
|
|
143
|
-
provider: "unknown",
|
|
144
|
-
id: claims.sub,
|
|
145
|
-
displayName: claims.name,
|
|
146
|
-
username: claims.email.split("@")[0].toLowerCase(),
|
|
147
|
-
name: {
|
|
148
|
-
familyName: claims.family_name,
|
|
149
|
-
givenName: claims.given_name
|
|
150
|
-
},
|
|
151
|
-
emails: [{ value: claims.email.toLowerCase() }],
|
|
152
|
-
photos: [{ value: claims.picture }]
|
|
153
|
-
};
|
|
154
|
-
return {
|
|
155
|
-
result: {
|
|
156
|
-
fullProfile,
|
|
157
|
-
accessToken,
|
|
158
|
-
expiresInSeconds: claims.exp
|
|
159
|
-
},
|
|
160
|
-
providerInfo: {
|
|
161
|
-
accessToken,
|
|
162
|
-
expiresInSeconds: claims.exp
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
} catch (e) {
|
|
166
|
-
throw new Error(`Exception occurred during JWT processing: ${e}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
exports.awsAlbSignInResolvers = void 0;
|
|
172
|
-
((awsAlbSignInResolvers2) => {
|
|
173
|
-
awsAlbSignInResolvers2.emailMatchingUserEntityProfileEmail = pluginAuthNode.createSignInResolverFactory({
|
|
174
|
-
create() {
|
|
175
|
-
return async (info, ctx) => {
|
|
176
|
-
if (!info.result.fullProfile.emails) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
"Login failed, user profile does not contain an email"
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
return ctx.signInWithCatalogUser({
|
|
182
|
-
filter: {
|
|
183
|
-
kind: ["User"],
|
|
184
|
-
"spec.profile.email": info.result.fullProfile.emails[0].value
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
})(exports.awsAlbSignInResolvers || (exports.awsAlbSignInResolvers = {}));
|
|
191
|
-
|
|
192
|
-
const authModuleAwsAlbProvider = backendPluginApi.createBackendModule({
|
|
193
|
-
pluginId: "auth",
|
|
194
|
-
moduleId: "awsAlbProvider",
|
|
195
|
-
register(reg) {
|
|
196
|
-
reg.registerInit({
|
|
197
|
-
deps: {
|
|
198
|
-
providers: pluginAuthNode.authProvidersExtensionPoint
|
|
199
|
-
},
|
|
200
|
-
async init({ providers }) {
|
|
201
|
-
providers.registerProvider({
|
|
202
|
-
providerId: "awsalb",
|
|
203
|
-
factory: pluginAuthNode.createProxyAuthProviderFactory({
|
|
204
|
-
authenticator: awsAlbAuthenticator,
|
|
205
|
-
signInResolverFactories: {
|
|
206
|
-
...pluginAuthNode.commonSignInResolvers,
|
|
207
|
-
...exports.awsAlbSignInResolvers
|
|
208
|
-
}
|
|
209
|
-
})
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
11
|
+
exports.awsAlbAuthenticator = authenticator.awsAlbAuthenticator;
|
|
12
|
+
exports.authModuleAwsAlbProvider = module$1.authModuleAwsAlbProvider;
|
|
13
|
+
exports.default = module$1.authModuleAwsAlbProvider;
|
|
14
|
+
Object.defineProperty(exports, "awsAlbSignInResolvers", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return resolvers.awsAlbSignInResolvers; }
|
|
214
17
|
});
|
|
215
|
-
|
|
216
|
-
exports.authModuleAwsAlbProvider = authModuleAwsAlbProvider;
|
|
217
|
-
exports.awsAlbAuthenticator = awsAlbAuthenticator;
|
|
218
|
-
exports.default = authModuleAwsAlbProvider;
|
|
219
18
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/helpers.ts","../src/authenticator.ts","../src/resolvers.ts","../src/module.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 */\nimport { KeyObject } from 'crypto';\nimport * as crypto from 'crypto';\nimport { JWTHeaderParameters, decodeJwt } from 'jose';\nimport NodeCache from 'node-cache';\nimport fetch from 'node-fetch';\nimport { PassportProfile, ProfileInfo } from '@backstage/plugin-auth-node';\nimport { AuthenticationError } from '@backstage/errors';\n\nexport const makeProfileInfo = (\n profile: PassportProfile,\n idToken?: string,\n): ProfileInfo => {\n let email: string | undefined = undefined;\n if (profile.emails && profile.emails.length > 0) {\n const [firstEmail] = profile.emails;\n email = firstEmail.value;\n }\n\n let picture: string | undefined = undefined;\n if (profile.avatarUrl) {\n picture = profile.avatarUrl;\n } else if (profile.photos && profile.photos.length > 0) {\n const [firstPhoto] = profile.photos;\n picture = firstPhoto.value;\n }\n\n let displayName: string | undefined =\n profile.displayName ?? profile.username ?? profile.id;\n\n if ((!email || !picture || !displayName) && idToken) {\n try {\n const decoded: Record<string, string> = decodeJwt(idToken) as {\n email?: string;\n picture?: string;\n name?: string;\n };\n if (!email && decoded.email) {\n email = decoded.email;\n }\n if (!picture && decoded.picture) {\n picture = decoded.picture;\n }\n if (!displayName && decoded.name) {\n displayName = decoded.name;\n }\n } catch (e) {\n throw new Error(`Failed to parse id token and get profile info, ${e}`);\n }\n }\n\n return {\n email,\n picture,\n displayName,\n };\n};\n\nconst getPublicKeyEndpoint = (region: string) => {\n if (region.startsWith('us-gov')) {\n return `https://s3-${encodeURIComponent(\n region,\n )}.amazonaws.com/aws-elb-public-keys-prod-${encodeURIComponent(region)}`;\n }\n\n return `https://public-keys.auth.elb.${encodeURIComponent(\n region,\n )}.amazonaws.com`;\n};\n\nexport const provisionKeyCache = (region: string, keyCache: NodeCache) => {\n return async (header: JWTHeaderParameters): Promise<KeyObject> => {\n if (!header.kid) {\n throw new AuthenticationError('No key id was specified in header');\n }\n const optionalCacheKey = keyCache.get<KeyObject>(header.kid);\n if (optionalCacheKey) {\n return crypto.createPublicKey(optionalCacheKey);\n }\n\n const keyText: string = await fetch(\n `${getPublicKeyEndpoint(region)}/${encodeURIComponent(header.kid)}`,\n ).then(response => response.text());\n\n const keyValue = crypto.createPublicKey(keyText);\n keyCache.set(header.kid, keyValue.export({ format: 'pem', type: 'spki' }));\n return keyValue;\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 { AuthenticationError } from '@backstage/errors';\nimport { AwsAlbClaims, AwsAlbProtectedHeader, AwsAlbResult } from './types';\nimport { jwtVerify } from 'jose';\nimport {\n createProxyAuthenticator,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\nimport NodeCache from 'node-cache';\nimport { makeProfileInfo, provisionKeyCache } from './helpers';\n\nexport const ALB_JWT_HEADER = 'x-amzn-oidc-data';\nexport const ALB_ACCESS_TOKEN_HEADER = 'x-amzn-oidc-accesstoken';\n\n/** @public */\nexport const awsAlbAuthenticator = createProxyAuthenticator({\n defaultProfileTransform: async (result: AwsAlbResult) => {\n return {\n profile: makeProfileInfo(result.fullProfile, result.accessToken),\n };\n },\n initialize({ config }) {\n const issuer = config.getString('issuer');\n const signer = config.getOptionalString('signer');\n const region = config.getString('region');\n const keyCache = new NodeCache({ stdTTL: 3600 });\n const getKey = provisionKeyCache(region, keyCache);\n return { issuer, signer, getKey };\n },\n async authenticate({ req }, { issuer, signer, getKey }) {\n const jwt = req.header(ALB_JWT_HEADER);\n const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);\n\n if (jwt === undefined) {\n throw new AuthenticationError(\n `Missing ALB OIDC header: ${ALB_JWT_HEADER}`,\n );\n }\n\n if (accessToken === undefined) {\n throw new AuthenticationError(\n `Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`,\n );\n }\n\n try {\n const verifyResult = await jwtVerify(jwt, getKey);\n const header = verifyResult.protectedHeader as AwsAlbProtectedHeader;\n const claims = verifyResult.payload as AwsAlbClaims;\n\n if (claims?.iss !== issuer) {\n throw new AuthenticationError('Issuer mismatch on JWT token');\n } else if (signer && header?.signer !== signer) {\n throw new AuthenticationError('Signer mismatch on JWT token');\n }\n\n if (!claims.email) {\n throw new AuthenticationError(`Missing email in the JWT token`);\n }\n\n const fullProfile: PassportProfile = {\n provider: 'unknown',\n id: claims.sub,\n displayName: claims.name,\n username: claims.email.split('@')[0].toLowerCase(),\n name: {\n familyName: claims.family_name,\n givenName: claims.given_name,\n },\n emails: [{ value: claims.email.toLowerCase() }],\n photos: [{ value: claims.picture }],\n };\n\n return {\n result: {\n fullProfile,\n accessToken: accessToken,\n expiresInSeconds: claims.exp,\n },\n providerInfo: {\n accessToken: accessToken,\n expiresInSeconds: claims.exp,\n },\n };\n } catch (e) {\n throw new Error(`Exception occurred during JWT processing: ${e}`);\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 createSignInResolverFactory,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\nimport { AwsAlbResult } from './types';\n/**\n * Available sign-in resolvers for the AWS ALB auth provider.\n *\n * @public\n */\nexport namespace awsAlbSignInResolvers {\n export const emailMatchingUserEntityProfileEmail =\n createSignInResolverFactory({\n create() {\n return async (info: SignInInfo<AwsAlbResult>, ctx) => {\n if (!info.result.fullProfile.emails) {\n throw new Error(\n 'Login failed, user profile does not contain an email',\n );\n }\n return ctx.signInWithCatalogUser({\n filter: {\n kind: ['User'],\n 'spec.profile.email': info.result.fullProfile.emails[0].value,\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 createProxyAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { awsAlbAuthenticator } from './authenticator';\nimport { awsAlbSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleAwsAlbProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'awsAlbProvider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'awsalb',\n factory: createProxyAuthProviderFactory({\n authenticator: awsAlbAuthenticator,\n signInResolverFactories: {\n ...commonSignInResolvers,\n ...awsAlbSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["decodeJwt","AuthenticationError","crypto","fetch","createProxyAuthenticator","NodeCache","jwtVerify","awsAlbSignInResolvers","createSignInResolverFactory","createBackendModule","authProvidersExtensionPoint","createProxyAuthProviderFact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AA,KAAA;AAAA,WAC1D;AAAA,SACD,CAAA,CAAA;AAAA,OACH,CAAA;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AAAA,CAlBY,EAAAD,6BAAA,KAAAA,6BAAA,GAAA,EAAA,CAAA,CAAA;;ACDV,MAAM,2BAA2BE,oCAAoB,CAAA;AAAA,EAC1D,QAAU,EAAA,MAAA;AAAA,EACV,QAAU,EAAA,gBAAA;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,QAAA;AAAA,UACZ,SAASC,6CAA+B,CAAA;AAAA,YACtC,aAAe,EAAA,mBAAA;AAAA,YACf,uBAAyB,EAAA;AAAA,cACvB,GAAGC,oCAAA;AAAA,cACH,GAAGL,6BAAA;AAAA,aACL;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
5
|
+
var authenticator = require('./authenticator.cjs.js');
|
|
6
|
+
var resolvers = require('./resolvers.cjs.js');
|
|
7
|
+
|
|
8
|
+
const authModuleAwsAlbProvider = backendPluginApi.createBackendModule({
|
|
9
|
+
pluginId: "auth",
|
|
10
|
+
moduleId: "awsAlbProvider",
|
|
11
|
+
register(reg) {
|
|
12
|
+
reg.registerInit({
|
|
13
|
+
deps: {
|
|
14
|
+
providers: pluginAuthNode.authProvidersExtensionPoint
|
|
15
|
+
},
|
|
16
|
+
async init({ providers }) {
|
|
17
|
+
providers.registerProvider({
|
|
18
|
+
providerId: "awsalb",
|
|
19
|
+
factory: pluginAuthNode.createProxyAuthProviderFactory({
|
|
20
|
+
authenticator: authenticator.awsAlbAuthenticator,
|
|
21
|
+
signInResolverFactories: {
|
|
22
|
+
...pluginAuthNode.commonSignInResolvers,
|
|
23
|
+
...resolvers.awsAlbSignInResolvers
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.authModuleAwsAlbProvider = authModuleAwsAlbProvider;
|
|
33
|
+
//# sourceMappingURL=module.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.cjs.js","sources":["../src/module.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 */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createProxyAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { awsAlbAuthenticator } from './authenticator';\nimport { awsAlbSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleAwsAlbProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'awsAlbProvider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'awsalb',\n factory: createProxyAuthProviderFactory({\n authenticator: awsAlbAuthenticator,\n signInResolverFactories: {\n ...commonSignInResolvers,\n ...awsAlbSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","authProvidersExtensionPoint","createProxyAuthProviderFactory","awsAlbAuthenticator","commonSignInResolvers","awsAlbSignInResolvers"],"mappings":";;;;;;;AAyBO,MAAM,2BAA2BA,oCAAoB,CAAA;AAAA,EAC1D,QAAU,EAAA,MAAA;AAAA,EACV,QAAU,EAAA,gBAAA;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,QAAA;AAAA,UACZ,SAASC,6CAA+B,CAAA;AAAA,YACtC,aAAe,EAAAC,iCAAA;AAAA,YACf,uBAAyB,EAAA;AAAA,cACvB,GAAGC,oCAAA;AAAA,cACH,GAAGC,+BAAA;AAAA,aACL;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
4
|
+
|
|
5
|
+
exports.awsAlbSignInResolvers = void 0;
|
|
6
|
+
((awsAlbSignInResolvers2) => {
|
|
7
|
+
awsAlbSignInResolvers2.emailMatchingUserEntityProfileEmail = pluginAuthNode.createSignInResolverFactory({
|
|
8
|
+
create() {
|
|
9
|
+
return async (info, ctx) => {
|
|
10
|
+
if (!info.result.fullProfile.emails) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Login failed, user profile does not contain an email"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return ctx.signInWithCatalogUser({
|
|
16
|
+
filter: {
|
|
17
|
+
kind: ["User"],
|
|
18
|
+
"spec.profile.email": info.result.fullProfile.emails[0].value
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
})(exports.awsAlbSignInResolvers || (exports.awsAlbSignInResolvers = {}));
|
|
25
|
+
//# sourceMappingURL=resolvers.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.cjs.js","sources":["../src/resolvers.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 {\n createSignInResolverFactory,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\nimport { AwsAlbResult } from './types';\n/**\n * Available sign-in resolvers for the AWS ALB auth provider.\n *\n * @public\n */\nexport namespace awsAlbSignInResolvers {\n export const emailMatchingUserEntityProfileEmail =\n createSignInResolverFactory({\n create() {\n return async (info: SignInInfo<AwsAlbResult>, ctx) => {\n if (!info.result.fullProfile.emails) {\n throw new Error(\n 'Login failed, user profile does not contain an email',\n );\n }\n return ctx.signInWithCatalogUser({\n filter: {\n kind: ['User'],\n 'spec.profile.email': info.result.fullProfile.emails[0].value,\n },\n });\n };\n },\n });\n}\n"],"names":["awsAlbSignInResolvers","createSignInResolverFactory"],"mappings":";;;;AA0BiBA,uCAAA;AAAA,CAAV,CAAUA,sBAAV,KAAA;AACE,EAAMA,sBAAAA,CAAA,sCACXC,0CAA4B,CAAA;AAAA,IAC1B,MAAS,GAAA;AACP,MAAO,OAAA,OAAO,MAAgC,GAAQ,KAAA;AACpD,QAAA,IAAI,CAAC,IAAA,CAAK,MAAO,CAAA,WAAA,CAAY,MAAQ,EAAA;AACnC,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,sDAAA;AAAA,WACF,CAAA;AAAA,SACF;AACA,QAAA,OAAO,IAAI,qBAAsB,CAAA;AAAA,UAC/B,MAAQ,EAAA;AAAA,YACN,IAAA,EAAM,CAAC,MAAM,CAAA;AAAA,YACb,sBAAsB,IAAK,CAAA,MAAA,CAAO,WAAY,CAAA,MAAA,CAAO,CAAC,CAAE,CAAA,KAAA;AAAA,WAC1D;AAAA,SACD,CAAA,CAAA;AAAA,OACH,CAAA;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AAAA,CAlBY,EAAAD,6BAAA,KAAAA,6BAAA,GAAA,EAAA,CAAA,CAAA;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-auth-backend-module-aws-alb-provider",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-next.1",
|
|
4
4
|
"description": "The aws-alb provider module for the Backstage auth backend.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@backstage/backend-common": "^0.25.0",
|
|
41
|
-
"@backstage/backend-plugin-api": "
|
|
42
|
-
"@backstage/errors": "
|
|
43
|
-
"@backstage/plugin-auth-backend": "
|
|
44
|
-
"@backstage/plugin-auth-node": "
|
|
41
|
+
"@backstage/backend-plugin-api": "1.0.1-next.1",
|
|
42
|
+
"@backstage/errors": "1.2.4",
|
|
43
|
+
"@backstage/plugin-auth-backend": "0.23.1-next.1",
|
|
44
|
+
"@backstage/plugin-auth-node": "0.5.3-next.1",
|
|
45
45
|
"jose": "^5.0.0",
|
|
46
46
|
"node-cache": "^5.1.2",
|
|
47
47
|
"node-fetch": "^2.7.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@backstage/backend-test-utils": "
|
|
51
|
-
"@backstage/cli": "
|
|
52
|
-
"@backstage/config": "
|
|
50
|
+
"@backstage/backend-test-utils": "1.0.1-next.2",
|
|
51
|
+
"@backstage/cli": "0.28.0-next.2",
|
|
52
|
+
"@backstage/config": "1.2.0",
|
|
53
53
|
"express": "^4.18.2",
|
|
54
54
|
"msw": "^2.0.8"
|
|
55
55
|
}
|