@backstage/plugin-auth-backend 0.18.6 → 0.18.8-next.0
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/config.d.ts +10 -0
- package/dist/index.cjs.js +253 -577
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +157 -317
- package/package.json +11 -5
package/dist/index.cjs.js
CHANGED
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
7
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
5
8
|
var express = require('express');
|
|
6
9
|
var Router = require('express-promise-router');
|
|
7
10
|
var cookieParser = require('cookie-parser');
|
|
8
11
|
var OAuth2Strategy = require('passport-oauth2');
|
|
9
|
-
var errors = require('@backstage/errors');
|
|
10
|
-
var pickBy = require('lodash/pickBy');
|
|
11
12
|
var crypto = require('crypto');
|
|
12
13
|
var url = require('url');
|
|
14
|
+
var errors = require('@backstage/errors');
|
|
13
15
|
var jwtDecoder = require('jwt-decode');
|
|
14
16
|
var Auth0InternalStrategy = require('passport-auth0');
|
|
15
17
|
var fetch = require('node-fetch');
|
|
16
18
|
var NodeCache = require('node-cache');
|
|
17
19
|
var jose = require('jose');
|
|
18
20
|
var passportBitbucketOauth2 = require('passport-bitbucket-oauth2');
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
+
var pluginAuthBackendModuleGcpIapProvider = require('@backstage/plugin-auth-backend-module-gcp-iap-provider');
|
|
22
|
+
var pluginAuthBackendModuleGithubProvider = require('@backstage/plugin-auth-backend-module-github-provider');
|
|
21
23
|
var passportGitlab2 = require('passport-gitlab2');
|
|
22
|
-
var
|
|
24
|
+
var pluginAuthBackendModuleGoogleProvider = require('@backstage/plugin-auth-backend-module-google-provider');
|
|
23
25
|
var passportMicrosoft = require('passport-microsoft');
|
|
24
|
-
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
25
26
|
var openidClient = require('openid-client');
|
|
26
27
|
var passportOktaOauth = require('@davidzemon/passport-okta-oauth');
|
|
27
28
|
var passportOneloginOauth = require('passport-onelogin-oauth');
|
|
@@ -63,7 +64,6 @@ var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
|
63
64
|
var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
|
|
64
65
|
var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
|
|
65
66
|
var OAuth2Strategy__default = /*#__PURE__*/_interopDefaultLegacy(OAuth2Strategy);
|
|
66
|
-
var pickBy__default = /*#__PURE__*/_interopDefaultLegacy(pickBy);
|
|
67
67
|
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
68
68
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
69
69
|
var jwtDecoder__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecoder);
|
|
@@ -74,10 +74,10 @@ var session__default = /*#__PURE__*/_interopDefaultLegacy(session);
|
|
|
74
74
|
var connectSessionKnex__default = /*#__PURE__*/_interopDefaultLegacy(connectSessionKnex);
|
|
75
75
|
var passport__default = /*#__PURE__*/_interopDefaultLegacy(passport);
|
|
76
76
|
|
|
77
|
-
var __defProp$
|
|
78
|
-
var __defNormalProp$
|
|
79
|
-
var __publicField$
|
|
80
|
-
__defNormalProp$
|
|
77
|
+
var __defProp$j = Object.defineProperty;
|
|
78
|
+
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
79
|
+
var __publicField$j = (obj, key, value) => {
|
|
80
|
+
__defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
81
81
|
return value;
|
|
82
82
|
};
|
|
83
83
|
const defaultScopes = ["offline_access", "read:me"];
|
|
@@ -94,7 +94,7 @@ class AtlassianStrategy extends OAuth2Strategy__default["default"] {
|
|
|
94
94
|
scope: Array.from(/* @__PURE__ */ new Set([...defaultScopes, ...scopes]))
|
|
95
95
|
};
|
|
96
96
|
super(optionsWithURLs, verify);
|
|
97
|
-
__publicField$
|
|
97
|
+
__publicField$j(this, "profileURL");
|
|
98
98
|
this.profileURL = "https://api.atlassian.com/me";
|
|
99
99
|
this.name = "atlassian";
|
|
100
100
|
this._oauth2.useAuthorizationHeaderforGET(true);
|
|
@@ -142,22 +142,10 @@ class AtlassianStrategy extends OAuth2Strategy__default["default"] {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
150
|
-
if (!state.nonce || !state.env || ((_a = state.nonce) == null ? void 0 : _a.length) === 0 || ((_b = state.env) == null ? void 0 : _b.length) === 0) {
|
|
151
|
-
throw Error(`Invalid state passed via request`);
|
|
152
|
-
}
|
|
153
|
-
return state;
|
|
154
|
-
};
|
|
155
|
-
const encodeState = (state) => {
|
|
156
|
-
const stateString = new URLSearchParams(
|
|
157
|
-
pickBy__default["default"](state, (value) => value !== void 0)
|
|
158
|
-
).toString();
|
|
159
|
-
return Buffer.from(stateString, "utf-8").toString("hex");
|
|
160
|
-
};
|
|
145
|
+
const OAuthEnvironmentHandler = pluginAuthNode.OAuthEnvironmentHandler;
|
|
146
|
+
|
|
147
|
+
const readState = pluginAuthNode.decodeOAuthState;
|
|
148
|
+
const encodeState = pluginAuthNode.encodeOAuthState;
|
|
161
149
|
const verifyNonce = (req, providerId) => {
|
|
162
150
|
var _a, _b;
|
|
163
151
|
const cookieNonce = req.cookies[`${providerId}-nonce`];
|
|
@@ -188,66 +176,6 @@ const defaultCookieConfigurer = ({
|
|
|
188
176
|
return { domain, path, secure, sameSite };
|
|
189
177
|
};
|
|
190
178
|
|
|
191
|
-
class OAuthEnvironmentHandler {
|
|
192
|
-
constructor(handlers) {
|
|
193
|
-
this.handlers = handlers;
|
|
194
|
-
}
|
|
195
|
-
static mapConfig(config, factoryFunc) {
|
|
196
|
-
const envs = config.keys();
|
|
197
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
198
|
-
for (const env of envs) {
|
|
199
|
-
const envConfig = config.getConfig(env);
|
|
200
|
-
const handler = factoryFunc(envConfig);
|
|
201
|
-
handlers.set(env, handler);
|
|
202
|
-
}
|
|
203
|
-
return new OAuthEnvironmentHandler(handlers);
|
|
204
|
-
}
|
|
205
|
-
async start(req, res) {
|
|
206
|
-
const provider = this.getProviderForEnv(req);
|
|
207
|
-
await provider.start(req, res);
|
|
208
|
-
}
|
|
209
|
-
async frameHandler(req, res) {
|
|
210
|
-
const provider = this.getProviderForEnv(req);
|
|
211
|
-
await provider.frameHandler(req, res);
|
|
212
|
-
}
|
|
213
|
-
async refresh(req, res) {
|
|
214
|
-
var _a;
|
|
215
|
-
const provider = this.getProviderForEnv(req);
|
|
216
|
-
await ((_a = provider.refresh) == null ? void 0 : _a.call(provider, req, res));
|
|
217
|
-
}
|
|
218
|
-
async logout(req, res) {
|
|
219
|
-
var _a;
|
|
220
|
-
const provider = this.getProviderForEnv(req);
|
|
221
|
-
await ((_a = provider.logout) == null ? void 0 : _a.call(provider, req, res));
|
|
222
|
-
}
|
|
223
|
-
getRequestFromEnv(req) {
|
|
224
|
-
var _a, _b;
|
|
225
|
-
const reqEnv = (_a = req.query.env) == null ? void 0 : _a.toString();
|
|
226
|
-
if (reqEnv) {
|
|
227
|
-
return reqEnv;
|
|
228
|
-
}
|
|
229
|
-
const stateParams = (_b = req.query.state) == null ? void 0 : _b.toString();
|
|
230
|
-
if (!stateParams) {
|
|
231
|
-
return void 0;
|
|
232
|
-
}
|
|
233
|
-
const env = readState(stateParams).env;
|
|
234
|
-
return env;
|
|
235
|
-
}
|
|
236
|
-
getProviderForEnv(req) {
|
|
237
|
-
const env = this.getRequestFromEnv(req);
|
|
238
|
-
if (!env) {
|
|
239
|
-
throw new errors.InputError(`Must specify 'env' query to select environment`);
|
|
240
|
-
}
|
|
241
|
-
const handler = this.handlers.get(env);
|
|
242
|
-
if (!handler) {
|
|
243
|
-
throw new errors.NotFoundError(
|
|
244
|
-
`No configuration available for the '${env}' environment of this provider.`
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
return handler;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
179
|
const safelyEncodeURIComponent = (value) => {
|
|
252
180
|
return encodeURIComponent(value).replace(/'/g, "%27");
|
|
253
181
|
};
|
|
@@ -279,26 +207,12 @@ const ensuresXRequestedWith = (req) => {
|
|
|
279
207
|
return true;
|
|
280
208
|
};
|
|
281
209
|
|
|
282
|
-
|
|
283
|
-
const [_header, payload, _signature] = token.split(".");
|
|
284
|
-
return JSON.parse(Buffer.from(payload, "base64").toString());
|
|
285
|
-
}
|
|
286
|
-
function prepareBackstageIdentityResponse(result) {
|
|
287
|
-
const { sub, ent } = parseJwtPayload(result.token);
|
|
288
|
-
return {
|
|
289
|
-
...result,
|
|
290
|
-
identity: {
|
|
291
|
-
type: "user",
|
|
292
|
-
userEntityRef: sub,
|
|
293
|
-
ownershipEntityRefs: ent != null ? ent : []
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
210
|
+
const prepareBackstageIdentityResponse = pluginAuthNode.prepareBackstageIdentityResponse;
|
|
297
211
|
|
|
298
|
-
var __defProp$
|
|
299
|
-
var __defNormalProp$
|
|
300
|
-
var __publicField$
|
|
301
|
-
__defNormalProp$
|
|
212
|
+
var __defProp$i = Object.defineProperty;
|
|
213
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
214
|
+
var __publicField$i = (obj, key, value) => {
|
|
215
|
+
__defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
302
216
|
return value;
|
|
303
217
|
};
|
|
304
218
|
const THOUSAND_DAYS_MS = 1e3 * 24 * 60 * 60 * 1e3;
|
|
@@ -307,8 +221,8 @@ class OAuthAdapter {
|
|
|
307
221
|
constructor(handlers, options) {
|
|
308
222
|
this.handlers = handlers;
|
|
309
223
|
this.options = options;
|
|
310
|
-
__publicField$
|
|
311
|
-
__publicField$
|
|
224
|
+
__publicField$i(this, "baseCookieOptions");
|
|
225
|
+
__publicField$i(this, "setNonceCookie", (res, nonce, cookieConfig) => {
|
|
312
226
|
res.cookie(`${this.options.providerId}-nonce`, nonce, {
|
|
313
227
|
maxAge: TEN_MINUTES_MS,
|
|
314
228
|
...this.baseCookieOptions,
|
|
@@ -316,34 +230,34 @@ class OAuthAdapter {
|
|
|
316
230
|
path: `${cookieConfig.path}/handler`
|
|
317
231
|
});
|
|
318
232
|
});
|
|
319
|
-
__publicField$
|
|
233
|
+
__publicField$i(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
|
|
320
234
|
res.cookie(`${this.options.providerId}-granted-scope`, scope, {
|
|
321
235
|
maxAge: THOUSAND_DAYS_MS,
|
|
322
236
|
...this.baseCookieOptions,
|
|
323
237
|
...cookieConfig
|
|
324
238
|
});
|
|
325
239
|
});
|
|
326
|
-
__publicField$
|
|
240
|
+
__publicField$i(this, "getRefreshTokenFromCookie", (req) => {
|
|
327
241
|
return req.cookies[`${this.options.providerId}-refresh-token`];
|
|
328
242
|
});
|
|
329
|
-
__publicField$
|
|
243
|
+
__publicField$i(this, "getGrantedScopeFromCookie", (req) => {
|
|
330
244
|
return req.cookies[`${this.options.providerId}-granted-scope`];
|
|
331
245
|
});
|
|
332
|
-
__publicField$
|
|
246
|
+
__publicField$i(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
|
|
333
247
|
res.cookie(`${this.options.providerId}-refresh-token`, refreshToken, {
|
|
334
248
|
maxAge: THOUSAND_DAYS_MS,
|
|
335
249
|
...this.baseCookieOptions,
|
|
336
250
|
...cookieConfig
|
|
337
251
|
});
|
|
338
252
|
});
|
|
339
|
-
__publicField$
|
|
253
|
+
__publicField$i(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
|
|
340
254
|
res.cookie(`${this.options.providerId}-refresh-token`, "", {
|
|
341
255
|
maxAge: 0,
|
|
342
256
|
...this.baseCookieOptions,
|
|
343
257
|
...cookieConfig
|
|
344
258
|
});
|
|
345
259
|
});
|
|
346
|
-
__publicField$
|
|
260
|
+
__publicField$i(this, "getCookieConfig", (origin) => {
|
|
347
261
|
return this.options.cookieConfigurer({
|
|
348
262
|
providerId: this.options.providerId,
|
|
349
263
|
baseUrl: this.options.baseUrl,
|
|
@@ -649,10 +563,10 @@ function createAuthProviderIntegration(config) {
|
|
|
649
563
|
});
|
|
650
564
|
}
|
|
651
565
|
|
|
652
|
-
var __defProp$
|
|
653
|
-
var __defNormalProp$
|
|
654
|
-
var __publicField$
|
|
655
|
-
__defNormalProp$
|
|
566
|
+
var __defProp$h = Object.defineProperty;
|
|
567
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
568
|
+
var __publicField$h = (obj, key, value) => {
|
|
569
|
+
__defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
656
570
|
return value;
|
|
657
571
|
};
|
|
658
572
|
const atlassianDefaultAuthHandler = async ({
|
|
@@ -663,10 +577,10 @@ const atlassianDefaultAuthHandler = async ({
|
|
|
663
577
|
});
|
|
664
578
|
class AtlassianAuthProvider {
|
|
665
579
|
constructor(options) {
|
|
666
|
-
__publicField$
|
|
667
|
-
__publicField$
|
|
668
|
-
__publicField$
|
|
669
|
-
__publicField$
|
|
580
|
+
__publicField$h(this, "_strategy");
|
|
581
|
+
__publicField$h(this, "signInResolver");
|
|
582
|
+
__publicField$h(this, "authHandler");
|
|
583
|
+
__publicField$h(this, "resolverContext");
|
|
670
584
|
this.resolverContext = options.resolverContext;
|
|
671
585
|
this.authHandler = options.authHandler;
|
|
672
586
|
this.signInResolver = options.signInResolver;
|
|
@@ -784,21 +698,21 @@ class Auth0Strategy extends Auth0InternalStrategy__default["default"] {
|
|
|
784
698
|
}
|
|
785
699
|
}
|
|
786
700
|
|
|
787
|
-
var __defProp$
|
|
788
|
-
var __defNormalProp$
|
|
789
|
-
var __publicField$
|
|
790
|
-
__defNormalProp$
|
|
701
|
+
var __defProp$g = Object.defineProperty;
|
|
702
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
703
|
+
var __publicField$g = (obj, key, value) => {
|
|
704
|
+
__defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
791
705
|
return value;
|
|
792
706
|
};
|
|
793
707
|
class Auth0AuthProvider {
|
|
794
708
|
constructor(options) {
|
|
795
|
-
__publicField$
|
|
796
|
-
__publicField$
|
|
797
|
-
__publicField$
|
|
798
|
-
__publicField$
|
|
799
|
-
__publicField$
|
|
800
|
-
__publicField$
|
|
801
|
-
__publicField$
|
|
709
|
+
__publicField$g(this, "_strategy");
|
|
710
|
+
__publicField$g(this, "signInResolver");
|
|
711
|
+
__publicField$g(this, "authHandler");
|
|
712
|
+
__publicField$g(this, "resolverContext");
|
|
713
|
+
__publicField$g(this, "audience");
|
|
714
|
+
__publicField$g(this, "connection");
|
|
715
|
+
__publicField$g(this, "connectionScope");
|
|
802
716
|
/**
|
|
803
717
|
* Due to passport-auth0 forcing options.state = true,
|
|
804
718
|
* passport-oauth2 requires express-session to be installed
|
|
@@ -807,7 +721,7 @@ class Auth0AuthProvider {
|
|
|
807
721
|
* passport-oauth2, which is the StateStore implementation used when options.state = false,
|
|
808
722
|
* allowing us to avoid using express-session in order to integrate with auth0.
|
|
809
723
|
*/
|
|
810
|
-
__publicField$
|
|
724
|
+
__publicField$g(this, "store", {
|
|
811
725
|
store(_req, cb) {
|
|
812
726
|
cb(null, null);
|
|
813
727
|
},
|
|
@@ -948,23 +862,23 @@ const auth0 = createAuthProviderIntegration({
|
|
|
948
862
|
}
|
|
949
863
|
});
|
|
950
864
|
|
|
951
|
-
var __defProp$
|
|
952
|
-
var __defNormalProp$
|
|
953
|
-
var __publicField$
|
|
954
|
-
__defNormalProp$
|
|
865
|
+
var __defProp$f = Object.defineProperty;
|
|
866
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
867
|
+
var __publicField$f = (obj, key, value) => {
|
|
868
|
+
__defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
955
869
|
return value;
|
|
956
870
|
};
|
|
957
871
|
const ALB_JWT_HEADER = "x-amzn-oidc-data";
|
|
958
872
|
const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
|
|
959
873
|
class AwsAlbAuthProvider {
|
|
960
874
|
constructor(options) {
|
|
961
|
-
__publicField$
|
|
962
|
-
__publicField$
|
|
963
|
-
__publicField$
|
|
964
|
-
__publicField$
|
|
965
|
-
__publicField$
|
|
966
|
-
__publicField$
|
|
967
|
-
__publicField$
|
|
875
|
+
__publicField$f(this, "region");
|
|
876
|
+
__publicField$f(this, "issuer");
|
|
877
|
+
__publicField$f(this, "resolverContext");
|
|
878
|
+
__publicField$f(this, "keyCache");
|
|
879
|
+
__publicField$f(this, "authHandler");
|
|
880
|
+
__publicField$f(this, "signInResolver");
|
|
881
|
+
__publicField$f(this, "getKey", async (header) => {
|
|
968
882
|
if (!header.kid) {
|
|
969
883
|
throw new errors.AuthenticationError("No key id was specified in header");
|
|
970
884
|
}
|
|
@@ -1092,18 +1006,18 @@ const awsAlb = createAuthProviderIntegration({
|
|
|
1092
1006
|
}
|
|
1093
1007
|
});
|
|
1094
1008
|
|
|
1095
|
-
var __defProp$
|
|
1096
|
-
var __defNormalProp$
|
|
1097
|
-
var __publicField$
|
|
1098
|
-
__defNormalProp$
|
|
1009
|
+
var __defProp$e = Object.defineProperty;
|
|
1010
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1011
|
+
var __publicField$e = (obj, key, value) => {
|
|
1012
|
+
__defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1099
1013
|
return value;
|
|
1100
1014
|
};
|
|
1101
1015
|
class BitbucketAuthProvider {
|
|
1102
1016
|
constructor(options) {
|
|
1103
|
-
__publicField$
|
|
1104
|
-
__publicField$
|
|
1105
|
-
__publicField$
|
|
1106
|
-
__publicField$
|
|
1017
|
+
__publicField$e(this, "_strategy");
|
|
1018
|
+
__publicField$e(this, "signInResolver");
|
|
1019
|
+
__publicField$e(this, "authHandler");
|
|
1020
|
+
__publicField$e(this, "resolverContext");
|
|
1107
1021
|
this.signInResolver = options.signInResolver;
|
|
1108
1022
|
this.authHandler = options.authHandler;
|
|
1109
1023
|
this.resolverContext = options.resolverContext;
|
|
@@ -1271,10 +1185,10 @@ const commonByEmailResolver = async (info, ctx) => {
|
|
|
1271
1185
|
});
|
|
1272
1186
|
};
|
|
1273
1187
|
|
|
1274
|
-
var __defProp$
|
|
1275
|
-
var __defNormalProp$
|
|
1276
|
-
var __publicField$
|
|
1277
|
-
__defNormalProp$
|
|
1188
|
+
var __defProp$d = Object.defineProperty;
|
|
1189
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1190
|
+
var __publicField$d = (obj, key, value) => {
|
|
1191
|
+
__defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1278
1192
|
return value;
|
|
1279
1193
|
};
|
|
1280
1194
|
const CF_JWT_HEADER = "cf-access-jwt-assertion";
|
|
@@ -1282,12 +1196,12 @@ const COOKIE_AUTH_NAME = "CF_Authorization";
|
|
|
1282
1196
|
const CACHE_PREFIX = "providers/cloudflare-access/profile-v1";
|
|
1283
1197
|
class CloudflareAccessAuthProvider {
|
|
1284
1198
|
constructor(options) {
|
|
1285
|
-
__publicField$
|
|
1286
|
-
__publicField$
|
|
1287
|
-
__publicField$
|
|
1288
|
-
__publicField$
|
|
1289
|
-
__publicField$
|
|
1290
|
-
__publicField$
|
|
1199
|
+
__publicField$d(this, "teamName");
|
|
1200
|
+
__publicField$d(this, "resolverContext");
|
|
1201
|
+
__publicField$d(this, "authHandler");
|
|
1202
|
+
__publicField$d(this, "signInResolver");
|
|
1203
|
+
__publicField$d(this, "jwtKeySet");
|
|
1204
|
+
__publicField$d(this, "cache");
|
|
1291
1205
|
this.teamName = options.teamName;
|
|
1292
1206
|
this.authHandler = options.authHandler;
|
|
1293
1207
|
this.signInResolver = options.signInResolver;
|
|
@@ -1425,272 +1339,52 @@ const cfAccess = createAuthProviderIntegration({
|
|
|
1425
1339
|
}
|
|
1426
1340
|
});
|
|
1427
1341
|
|
|
1428
|
-
function createTokenValidator(audience, mockClient) {
|
|
1429
|
-
const client = mockClient != null ? mockClient : new googleAuthLibrary.OAuth2Client();
|
|
1430
|
-
return async function tokenValidator(token) {
|
|
1431
|
-
const response = await client.getIapPublicKeys();
|
|
1432
|
-
const ticket = await client.verifySignedJwtWithCertsAsync(
|
|
1433
|
-
token,
|
|
1434
|
-
response.pubkeys,
|
|
1435
|
-
audience,
|
|
1436
|
-
["https://cloud.google.com/iap"]
|
|
1437
|
-
);
|
|
1438
|
-
const payload = ticket.getPayload();
|
|
1439
|
-
if (!payload) {
|
|
1440
|
-
throw new TypeError("Token had no payload");
|
|
1441
|
-
}
|
|
1442
|
-
return payload;
|
|
1443
|
-
};
|
|
1444
|
-
}
|
|
1445
|
-
async function parseRequestToken(jwtToken, tokenValidator) {
|
|
1446
|
-
if (typeof jwtToken !== "string" || !jwtToken) {
|
|
1447
|
-
throw new errors.AuthenticationError("Missing Google IAP header");
|
|
1448
|
-
}
|
|
1449
|
-
let payload;
|
|
1450
|
-
try {
|
|
1451
|
-
payload = await tokenValidator(jwtToken);
|
|
1452
|
-
} catch (e) {
|
|
1453
|
-
throw new errors.AuthenticationError(`Google IAP token verification failed, ${e}`);
|
|
1454
|
-
}
|
|
1455
|
-
if (!payload.sub || !payload.email) {
|
|
1456
|
-
throw new errors.AuthenticationError(
|
|
1457
|
-
"Google IAP token payload is missing sub and/or email claim"
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
return {
|
|
1461
|
-
iapToken: {
|
|
1462
|
-
...payload,
|
|
1463
|
-
sub: payload.sub,
|
|
1464
|
-
email: payload.email
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
|
-
const defaultAuthHandler$1 = async ({
|
|
1469
|
-
iapToken
|
|
1470
|
-
}) => ({ profile: { email: iapToken.email } });
|
|
1471
|
-
|
|
1472
|
-
const DEFAULT_IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
|
|
1473
|
-
|
|
1474
|
-
var __defProp$f = Object.defineProperty;
|
|
1475
|
-
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1476
|
-
var __publicField$f = (obj, key, value) => {
|
|
1477
|
-
__defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1478
|
-
return value;
|
|
1479
|
-
};
|
|
1480
|
-
class GcpIapProvider {
|
|
1481
|
-
constructor(options) {
|
|
1482
|
-
__publicField$f(this, "authHandler");
|
|
1483
|
-
__publicField$f(this, "signInResolver");
|
|
1484
|
-
__publicField$f(this, "tokenValidator");
|
|
1485
|
-
__publicField$f(this, "resolverContext");
|
|
1486
|
-
__publicField$f(this, "jwtHeader");
|
|
1487
|
-
this.authHandler = options.authHandler;
|
|
1488
|
-
this.signInResolver = options.signInResolver;
|
|
1489
|
-
this.tokenValidator = options.tokenValidator;
|
|
1490
|
-
this.resolverContext = options.resolverContext;
|
|
1491
|
-
this.jwtHeader = (options == null ? void 0 : options.jwtHeader) || DEFAULT_IAP_JWT_HEADER;
|
|
1492
|
-
}
|
|
1493
|
-
async start() {
|
|
1494
|
-
}
|
|
1495
|
-
async frameHandler() {
|
|
1496
|
-
}
|
|
1497
|
-
async refresh(req, res) {
|
|
1498
|
-
const result = await parseRequestToken(
|
|
1499
|
-
req.header(this.jwtHeader),
|
|
1500
|
-
this.tokenValidator
|
|
1501
|
-
);
|
|
1502
|
-
const { profile } = await this.authHandler(result, this.resolverContext);
|
|
1503
|
-
const backstageIdentity = await this.signInResolver(
|
|
1504
|
-
{ profile, result },
|
|
1505
|
-
this.resolverContext
|
|
1506
|
-
);
|
|
1507
|
-
const response = {
|
|
1508
|
-
providerInfo: { iapToken: result.iapToken },
|
|
1509
|
-
profile,
|
|
1510
|
-
backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity)
|
|
1511
|
-
};
|
|
1512
|
-
res.json(response);
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
1342
|
const gcpIap = createAuthProviderIntegration({
|
|
1516
1343
|
create(options) {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
const tokenValidator = createTokenValidator(audience);
|
|
1524
|
-
return new GcpIapProvider({
|
|
1525
|
-
authHandler,
|
|
1526
|
-
signInResolver,
|
|
1527
|
-
tokenValidator,
|
|
1528
|
-
resolverContext,
|
|
1529
|
-
jwtHeader
|
|
1530
|
-
});
|
|
1531
|
-
};
|
|
1344
|
+
var _a;
|
|
1345
|
+
return pluginAuthNode.createProxyAuthProviderFactory({
|
|
1346
|
+
authenticator: pluginAuthBackendModuleGcpIapProvider.gcpIapAuthenticator,
|
|
1347
|
+
profileTransform: options == null ? void 0 : options.authHandler,
|
|
1348
|
+
signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver
|
|
1349
|
+
});
|
|
1532
1350
|
}
|
|
1533
1351
|
});
|
|
1534
1352
|
|
|
1535
|
-
const BACKSTAGE_SESSION_EXPIRATION = 3600;
|
|
1536
|
-
|
|
1537
|
-
var __defProp$e = Object.defineProperty;
|
|
1538
|
-
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1539
|
-
var __publicField$e = (obj, key, value) => {
|
|
1540
|
-
__defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1541
|
-
return value;
|
|
1542
|
-
};
|
|
1543
|
-
const ACCESS_TOKEN_PREFIX = "access-token.";
|
|
1544
|
-
class GithubAuthProvider {
|
|
1545
|
-
constructor(options) {
|
|
1546
|
-
__publicField$e(this, "_strategy");
|
|
1547
|
-
__publicField$e(this, "signInResolver");
|
|
1548
|
-
__publicField$e(this, "authHandler");
|
|
1549
|
-
__publicField$e(this, "resolverContext");
|
|
1550
|
-
__publicField$e(this, "stateEncoder");
|
|
1551
|
-
this.signInResolver = options.signInResolver;
|
|
1552
|
-
this.authHandler = options.authHandler;
|
|
1553
|
-
this.stateEncoder = options.stateEncoder;
|
|
1554
|
-
this.resolverContext = options.resolverContext;
|
|
1555
|
-
this._strategy = new passportGithub2.Strategy(
|
|
1556
|
-
{
|
|
1557
|
-
clientID: options.clientId,
|
|
1558
|
-
clientSecret: options.clientSecret,
|
|
1559
|
-
callbackURL: options.callbackUrl,
|
|
1560
|
-
tokenURL: options.tokenUrl,
|
|
1561
|
-
userProfileURL: options.userProfileUrl,
|
|
1562
|
-
authorizationURL: options.authorizationUrl
|
|
1563
|
-
},
|
|
1564
|
-
(accessToken, refreshToken, params, fullProfile, done) => {
|
|
1565
|
-
done(void 0, { fullProfile, params, accessToken }, { refreshToken });
|
|
1566
|
-
}
|
|
1567
|
-
);
|
|
1568
|
-
}
|
|
1569
|
-
async start(req) {
|
|
1570
|
-
return await executeRedirectStrategy(req, this._strategy, {
|
|
1571
|
-
scope: req.scope,
|
|
1572
|
-
state: (await this.stateEncoder(req)).encodedState
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
async handler(req) {
|
|
1576
|
-
const { result, privateInfo } = await executeFrameHandlerStrategy(req, this._strategy);
|
|
1577
|
-
let refreshToken = privateInfo.refreshToken;
|
|
1578
|
-
if (!refreshToken && !result.params.expires_in) {
|
|
1579
|
-
refreshToken = ACCESS_TOKEN_PREFIX + result.accessToken;
|
|
1580
|
-
}
|
|
1581
|
-
return {
|
|
1582
|
-
response: await this.handleResult(result),
|
|
1583
|
-
refreshToken
|
|
1584
|
-
};
|
|
1585
|
-
}
|
|
1586
|
-
async refresh(req) {
|
|
1587
|
-
const { scope, refreshToken } = req;
|
|
1588
|
-
if (refreshToken == null ? void 0 : refreshToken.startsWith(ACCESS_TOKEN_PREFIX)) {
|
|
1589
|
-
const accessToken = refreshToken.slice(ACCESS_TOKEN_PREFIX.length);
|
|
1590
|
-
const fullProfile = await executeFetchUserProfileStrategy(
|
|
1591
|
-
this._strategy,
|
|
1592
|
-
accessToken
|
|
1593
|
-
).catch((error) => {
|
|
1594
|
-
var _a;
|
|
1595
|
-
if (((_a = error.oauthError) == null ? void 0 : _a.statusCode) === 401) {
|
|
1596
|
-
throw new Error("Invalid access token");
|
|
1597
|
-
}
|
|
1598
|
-
throw error;
|
|
1599
|
-
});
|
|
1600
|
-
return {
|
|
1601
|
-
response: await this.handleResult({
|
|
1602
|
-
fullProfile,
|
|
1603
|
-
params: { scope },
|
|
1604
|
-
accessToken
|
|
1605
|
-
}),
|
|
1606
|
-
refreshToken
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
const result = await executeRefreshTokenStrategy(
|
|
1610
|
-
this._strategy,
|
|
1611
|
-
refreshToken,
|
|
1612
|
-
scope
|
|
1613
|
-
);
|
|
1614
|
-
return {
|
|
1615
|
-
response: await this.handleResult({
|
|
1616
|
-
fullProfile: await executeFetchUserProfileStrategy(
|
|
1617
|
-
this._strategy,
|
|
1618
|
-
result.accessToken
|
|
1619
|
-
),
|
|
1620
|
-
params: { ...result.params, scope },
|
|
1621
|
-
accessToken: result.accessToken
|
|
1622
|
-
}),
|
|
1623
|
-
refreshToken: result.refreshToken
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
async handleResult(result) {
|
|
1627
|
-
const { profile } = await this.authHandler(result, this.resolverContext);
|
|
1628
|
-
const expiresInStr = result.params.expires_in;
|
|
1629
|
-
let expiresInSeconds = expiresInStr === void 0 ? void 0 : Number(expiresInStr);
|
|
1630
|
-
let backstageIdentity = void 0;
|
|
1631
|
-
if (this.signInResolver) {
|
|
1632
|
-
backstageIdentity = await this.signInResolver(
|
|
1633
|
-
{
|
|
1634
|
-
result,
|
|
1635
|
-
profile
|
|
1636
|
-
},
|
|
1637
|
-
this.resolverContext
|
|
1638
|
-
);
|
|
1639
|
-
if (expiresInSeconds) {
|
|
1640
|
-
expiresInSeconds = Math.min(
|
|
1641
|
-
expiresInSeconds,
|
|
1642
|
-
BACKSTAGE_SESSION_EXPIRATION
|
|
1643
|
-
);
|
|
1644
|
-
} else {
|
|
1645
|
-
expiresInSeconds = BACKSTAGE_SESSION_EXPIRATION;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
return {
|
|
1649
|
-
backstageIdentity,
|
|
1650
|
-
providerInfo: {
|
|
1651
|
-
accessToken: result.accessToken,
|
|
1652
|
-
scope: result.params.scope,
|
|
1653
|
-
expiresInSeconds
|
|
1654
|
-
},
|
|
1655
|
-
profile
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
1353
|
const github = createAuthProviderIntegration({
|
|
1660
1354
|
create(options) {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1355
|
+
var _a;
|
|
1356
|
+
const authHandler = options == null ? void 0 : options.authHandler;
|
|
1357
|
+
const signInResolver = (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver;
|
|
1358
|
+
return pluginAuthNode.createOAuthProviderFactory({
|
|
1359
|
+
authenticator: pluginAuthBackendModuleGithubProvider.githubAuthenticator,
|
|
1360
|
+
profileTransform: authHandler && (async (result, ctx) => authHandler(
|
|
1361
|
+
{
|
|
1362
|
+
fullProfile: result.fullProfile,
|
|
1363
|
+
accessToken: result.session.accessToken,
|
|
1364
|
+
params: {
|
|
1365
|
+
scope: result.session.scope,
|
|
1366
|
+
expires_in: result.session.expiresInSeconds ? String(result.session.expiresInSeconds) : "",
|
|
1367
|
+
refresh_token_expires_in: result.session.refreshTokenExpiresInSeconds ? String(result.session.refreshTokenExpiresInSeconds) : ""
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
ctx
|
|
1371
|
+
)),
|
|
1372
|
+
signInResolver: signInResolver && (async ({ profile, result }, ctx) => signInResolver(
|
|
1373
|
+
{
|
|
1374
|
+
profile,
|
|
1375
|
+
result: {
|
|
1376
|
+
fullProfile: result.fullProfile,
|
|
1377
|
+
accessToken: result.session.accessToken,
|
|
1378
|
+
refreshToken: result.session.refreshToken,
|
|
1379
|
+
params: {
|
|
1380
|
+
scope: result.session.scope,
|
|
1381
|
+
expires_in: result.session.expiresInSeconds ? String(result.session.expiresInSeconds) : "",
|
|
1382
|
+
refresh_token_expires_in: result.session.refreshTokenExpiresInSeconds ? String(result.session.refreshTokenExpiresInSeconds) : ""
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
ctx
|
|
1387
|
+
))
|
|
1694
1388
|
});
|
|
1695
1389
|
},
|
|
1696
1390
|
resolvers: {
|
|
@@ -1710,10 +1404,10 @@ const github = createAuthProviderIntegration({
|
|
|
1710
1404
|
}
|
|
1711
1405
|
});
|
|
1712
1406
|
|
|
1713
|
-
var __defProp$
|
|
1714
|
-
var __defNormalProp$
|
|
1715
|
-
var __publicField$
|
|
1716
|
-
__defNormalProp$
|
|
1407
|
+
var __defProp$c = Object.defineProperty;
|
|
1408
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1409
|
+
var __publicField$c = (obj, key, value) => {
|
|
1410
|
+
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1717
1411
|
return value;
|
|
1718
1412
|
};
|
|
1719
1413
|
const gitlabDefaultAuthHandler = async ({
|
|
@@ -1724,10 +1418,10 @@ const gitlabDefaultAuthHandler = async ({
|
|
|
1724
1418
|
});
|
|
1725
1419
|
class GitlabAuthProvider {
|
|
1726
1420
|
constructor(options) {
|
|
1727
|
-
__publicField$
|
|
1728
|
-
__publicField$
|
|
1729
|
-
__publicField$
|
|
1730
|
-
__publicField$
|
|
1421
|
+
__publicField$c(this, "_strategy");
|
|
1422
|
+
__publicField$c(this, "signInResolver");
|
|
1423
|
+
__publicField$c(this, "authHandler");
|
|
1424
|
+
__publicField$c(this, "resolverContext");
|
|
1731
1425
|
this.resolverContext = options.resolverContext;
|
|
1732
1426
|
this.authHandler = options.authHandler;
|
|
1733
1427
|
this.signInResolver = options.signInResolver;
|
|
@@ -1835,158 +1529,88 @@ const gitlab = createAuthProviderIntegration({
|
|
|
1835
1529
|
}
|
|
1836
1530
|
});
|
|
1837
1531
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
__publicField$c(this, "authHandler");
|
|
1849
|
-
__publicField$c(this, "resolverContext");
|
|
1850
|
-
this.authHandler = options.authHandler;
|
|
1851
|
-
this.signInResolver = options.signInResolver;
|
|
1852
|
-
this.resolverContext = options.resolverContext;
|
|
1853
|
-
this.strategy = new passportGoogleOauth20.Strategy(
|
|
1854
|
-
{
|
|
1855
|
-
clientID: options.clientId,
|
|
1856
|
-
clientSecret: options.clientSecret,
|
|
1857
|
-
callbackURL: options.callbackUrl,
|
|
1858
|
-
passReqToCallback: false
|
|
1859
|
-
},
|
|
1860
|
-
(accessToken, refreshToken, params, fullProfile, done) => {
|
|
1861
|
-
done(
|
|
1862
|
-
void 0,
|
|
1863
|
-
{
|
|
1864
|
-
fullProfile,
|
|
1865
|
-
params,
|
|
1866
|
-
accessToken,
|
|
1867
|
-
refreshToken
|
|
1868
|
-
},
|
|
1869
|
-
{
|
|
1870
|
-
refreshToken
|
|
1871
|
-
}
|
|
1872
|
-
);
|
|
1532
|
+
function adaptLegacyOAuthHandler(authHandler) {
|
|
1533
|
+
return authHandler && (async (result, ctx) => authHandler(
|
|
1534
|
+
{
|
|
1535
|
+
fullProfile: result.fullProfile,
|
|
1536
|
+
accessToken: result.session.accessToken,
|
|
1537
|
+
params: {
|
|
1538
|
+
scope: result.session.scope,
|
|
1539
|
+
id_token: result.session.idToken,
|
|
1540
|
+
token_type: result.session.tokenType,
|
|
1541
|
+
expires_in: result.session.expiresInSeconds
|
|
1873
1542
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
response: await this.handleResult({
|
|
1907
|
-
fullProfile,
|
|
1908
|
-
params,
|
|
1909
|
-
accessToken
|
|
1910
|
-
}),
|
|
1911
|
-
refreshToken
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
async handleResult(result) {
|
|
1915
|
-
const { profile } = await this.authHandler(result, this.resolverContext);
|
|
1916
|
-
const response = {
|
|
1917
|
-
providerInfo: {
|
|
1918
|
-
idToken: result.params.id_token,
|
|
1919
|
-
accessToken: result.accessToken,
|
|
1920
|
-
scope: result.params.scope,
|
|
1921
|
-
expiresInSeconds: result.params.expires_in
|
|
1922
|
-
},
|
|
1923
|
-
profile
|
|
1924
|
-
};
|
|
1925
|
-
if (this.signInResolver) {
|
|
1926
|
-
response.backstageIdentity = await this.signInResolver(
|
|
1543
|
+
},
|
|
1544
|
+
ctx
|
|
1545
|
+
));
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function adaptLegacyOAuthSignInResolver(signInResolver) {
|
|
1549
|
+
return signInResolver && (async (input, ctx) => signInResolver(
|
|
1550
|
+
{
|
|
1551
|
+
profile: input.profile,
|
|
1552
|
+
result: {
|
|
1553
|
+
fullProfile: input.result.fullProfile,
|
|
1554
|
+
accessToken: input.result.session.accessToken,
|
|
1555
|
+
refreshToken: input.result.session.refreshToken,
|
|
1556
|
+
params: {
|
|
1557
|
+
scope: input.result.session.scope,
|
|
1558
|
+
id_token: input.result.session.idToken,
|
|
1559
|
+
token_type: input.result.session.tokenType,
|
|
1560
|
+
expires_in: input.result.session.expiresInSeconds
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
},
|
|
1564
|
+
ctx
|
|
1565
|
+
));
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
function adaptOAuthSignInResolverToLegacy(resolvers) {
|
|
1569
|
+
const legacyResolvers = {};
|
|
1570
|
+
for (const name of Object.keys(resolvers)) {
|
|
1571
|
+
const resolver = resolvers[name];
|
|
1572
|
+
legacyResolvers[name] = () => async (input, ctx) => {
|
|
1573
|
+
var _a;
|
|
1574
|
+
return resolver(
|
|
1927
1575
|
{
|
|
1928
|
-
|
|
1929
|
-
|
|
1576
|
+
profile: input.profile,
|
|
1577
|
+
result: {
|
|
1578
|
+
fullProfile: input.result.fullProfile,
|
|
1579
|
+
session: {
|
|
1580
|
+
accessToken: input.result.accessToken,
|
|
1581
|
+
expiresInSeconds: input.result.params.expires_in,
|
|
1582
|
+
scope: input.result.params.scope,
|
|
1583
|
+
idToken: input.result.params.id_token,
|
|
1584
|
+
tokenType: (_a = input.result.params.token_type) != null ? _a : "bearer",
|
|
1585
|
+
refreshToken: input.result.refreshToken
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1930
1588
|
},
|
|
1931
|
-
|
|
1589
|
+
ctx
|
|
1932
1590
|
);
|
|
1933
|
-
}
|
|
1934
|
-
return response;
|
|
1591
|
+
};
|
|
1935
1592
|
}
|
|
1593
|
+
return legacyResolvers;
|
|
1936
1594
|
}
|
|
1595
|
+
|
|
1937
1596
|
const google = createAuthProviderIntegration({
|
|
1938
1597
|
create(options) {
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
|
|
1945
|
-
const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile, params }) => ({
|
|
1946
|
-
profile: makeProfileInfo(fullProfile, params.id_token)
|
|
1947
|
-
});
|
|
1948
|
-
const provider = new GoogleAuthProvider({
|
|
1949
|
-
clientId,
|
|
1950
|
-
clientSecret,
|
|
1951
|
-
callbackUrl,
|
|
1952
|
-
signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver,
|
|
1953
|
-
authHandler,
|
|
1954
|
-
resolverContext
|
|
1955
|
-
});
|
|
1956
|
-
return OAuthAdapter.fromConfig(globalConfig, provider, {
|
|
1957
|
-
providerId,
|
|
1958
|
-
callbackUrl
|
|
1959
|
-
});
|
|
1598
|
+
var _a;
|
|
1599
|
+
return pluginAuthNode.createOAuthProviderFactory({
|
|
1600
|
+
authenticator: pluginAuthBackendModuleGoogleProvider.googleAuthenticator,
|
|
1601
|
+
profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
|
|
1602
|
+
signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
|
|
1960
1603
|
});
|
|
1961
1604
|
},
|
|
1962
|
-
resolvers: {
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
/**
|
|
1968
|
-
* Looks up the user by matching their email to the entity email.
|
|
1969
|
-
*/
|
|
1970
|
-
emailMatchingUserEntityProfileEmail: () => commonByEmailResolver,
|
|
1971
|
-
/**
|
|
1972
|
-
* Looks up the user by matching their email to the `google.com/email` annotation.
|
|
1973
|
-
*/
|
|
1974
|
-
emailMatchingUserEntityAnnotation() {
|
|
1975
|
-
return async (info, ctx) => {
|
|
1976
|
-
const { profile } = info;
|
|
1977
|
-
if (!profile.email) {
|
|
1978
|
-
throw new Error("Google profile contained no email");
|
|
1979
|
-
}
|
|
1980
|
-
return ctx.signInWithCatalogUser({
|
|
1981
|
-
annotations: {
|
|
1982
|
-
"google.com/email": profile.email
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
};
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1605
|
+
resolvers: adaptOAuthSignInResolverToLegacy({
|
|
1606
|
+
emailLocalPartMatchingUserEntityName: pluginAuthNode.commonSignInResolvers.emailLocalPartMatchingUserEntityName(),
|
|
1607
|
+
emailMatchingUserEntityProfileEmail: pluginAuthNode.commonSignInResolvers.emailMatchingUserEntityProfileEmail(),
|
|
1608
|
+
emailMatchingUserEntityAnnotation: pluginAuthBackendModuleGoogleProvider.googleSignInResolvers.emailMatchingUserEntityAnnotation()
|
|
1609
|
+
})
|
|
1988
1610
|
});
|
|
1989
1611
|
|
|
1612
|
+
const BACKSTAGE_SESSION_EXPIRATION = 3600;
|
|
1613
|
+
|
|
1990
1614
|
var __defProp$b = Object.defineProperty;
|
|
1991
1615
|
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1992
1616
|
var __publicField$b = (obj, key, value) => {
|
|
@@ -3873,7 +3497,7 @@ async function createRouter(options) {
|
|
|
3873
3497
|
database,
|
|
3874
3498
|
tokenManager,
|
|
3875
3499
|
tokenFactoryAlgorithm,
|
|
3876
|
-
providerFactories,
|
|
3500
|
+
providerFactories = {},
|
|
3877
3501
|
catalogApi
|
|
3878
3502
|
} = options;
|
|
3879
3503
|
const router = Router__default["default"]();
|
|
@@ -3890,7 +3514,7 @@ async function createRouter(options) {
|
|
|
3890
3514
|
keyStore,
|
|
3891
3515
|
keyDurationSeconds,
|
|
3892
3516
|
logger: logger.child({ component: "token-factory" }),
|
|
3893
|
-
algorithm: tokenFactoryAlgorithm
|
|
3517
|
+
algorithm: tokenFactoryAlgorithm != null ? tokenFactoryAlgorithm : config.getOptionalString("auth.identityTokenAlgorithm")
|
|
3894
3518
|
});
|
|
3895
3519
|
const secret = config.getOptionalString("auth.session.secret");
|
|
3896
3520
|
if (secret) {
|
|
@@ -3916,21 +3540,23 @@ async function createRouter(options) {
|
|
|
3916
3540
|
}
|
|
3917
3541
|
router.use(express__default["default"].urlencoded({ extended: false }));
|
|
3918
3542
|
router.use(express__default["default"].json());
|
|
3919
|
-
const allProviderFactories = {
|
|
3543
|
+
const allProviderFactories = options.disableDefaultProviderFactories ? providerFactories : {
|
|
3920
3544
|
...defaultAuthProviderFactories,
|
|
3921
3545
|
...providerFactories
|
|
3922
3546
|
};
|
|
3923
|
-
const providersConfig = config.
|
|
3924
|
-
const configuredProviders = providersConfig.keys();
|
|
3547
|
+
const providersConfig = config.getOptionalConfig("auth.providers");
|
|
3925
3548
|
const isOriginAllowed = createOriginFilter(config);
|
|
3926
3549
|
for (const [providerId, providerFactory] of Object.entries(
|
|
3927
3550
|
allProviderFactories
|
|
3928
3551
|
)) {
|
|
3929
|
-
if (
|
|
3552
|
+
if (providersConfig == null ? void 0 : providersConfig.has(providerId)) {
|
|
3930
3553
|
logger.info(`Configuring auth provider: ${providerId}`);
|
|
3931
3554
|
try {
|
|
3932
3555
|
const provider = providerFactory({
|
|
3933
3556
|
providerId,
|
|
3557
|
+
appUrl,
|
|
3558
|
+
baseUrl: authUrl,
|
|
3559
|
+
isOriginAllowed,
|
|
3934
3560
|
globalConfig: {
|
|
3935
3561
|
baseUrl: authUrl,
|
|
3936
3562
|
appUrl,
|
|
@@ -4009,9 +3635,59 @@ function createOriginFilter(config) {
|
|
|
4009
3635
|
};
|
|
4010
3636
|
}
|
|
4011
3637
|
|
|
3638
|
+
const authPlugin = backendPluginApi.createBackendPlugin({
|
|
3639
|
+
pluginId: "auth",
|
|
3640
|
+
register(reg) {
|
|
3641
|
+
const providers = /* @__PURE__ */ new Map();
|
|
3642
|
+
reg.registerExtensionPoint(pluginAuthNode.authProvidersExtensionPoint, {
|
|
3643
|
+
registerProvider({ providerId, factory }) {
|
|
3644
|
+
if (providers.has(providerId)) {
|
|
3645
|
+
throw new Error(
|
|
3646
|
+
`Auth provider '${providerId}' was already registered`
|
|
3647
|
+
);
|
|
3648
|
+
}
|
|
3649
|
+
providers.set(providerId, factory);
|
|
3650
|
+
}
|
|
3651
|
+
});
|
|
3652
|
+
reg.registerInit({
|
|
3653
|
+
deps: {
|
|
3654
|
+
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
3655
|
+
logger: backendPluginApi.coreServices.logger,
|
|
3656
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
3657
|
+
database: backendPluginApi.coreServices.database,
|
|
3658
|
+
discovery: backendPluginApi.coreServices.discovery,
|
|
3659
|
+
tokenManager: backendPluginApi.coreServices.tokenManager,
|
|
3660
|
+
catalogApi: alpha.catalogServiceRef
|
|
3661
|
+
},
|
|
3662
|
+
async init({
|
|
3663
|
+
httpRouter,
|
|
3664
|
+
logger,
|
|
3665
|
+
config,
|
|
3666
|
+
database,
|
|
3667
|
+
discovery,
|
|
3668
|
+
tokenManager,
|
|
3669
|
+
catalogApi
|
|
3670
|
+
}) {
|
|
3671
|
+
const router = await createRouter({
|
|
3672
|
+
logger,
|
|
3673
|
+
config,
|
|
3674
|
+
database,
|
|
3675
|
+
discovery,
|
|
3676
|
+
tokenManager,
|
|
3677
|
+
catalogApi,
|
|
3678
|
+
providerFactories: Object.fromEntries(providers),
|
|
3679
|
+
disableDefaultProviderFactories: true
|
|
3680
|
+
});
|
|
3681
|
+
httpRouter.use(router);
|
|
3682
|
+
}
|
|
3683
|
+
});
|
|
3684
|
+
}
|
|
3685
|
+
});
|
|
3686
|
+
|
|
4012
3687
|
exports.CatalogIdentityClient = CatalogIdentityClient;
|
|
4013
3688
|
exports.OAuthAdapter = OAuthAdapter;
|
|
4014
3689
|
exports.OAuthEnvironmentHandler = OAuthEnvironmentHandler;
|
|
3690
|
+
exports.authPlugin = authPlugin;
|
|
4015
3691
|
exports.createAuthProviderIntegration = createAuthProviderIntegration;
|
|
4016
3692
|
exports.createOriginFilter = createOriginFilter;
|
|
4017
3693
|
exports.createRouter = createRouter;
|