@simulacrum/auth0-simulator 0.8.0 → 0.8.2
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 +15 -0
- package/README.md +2 -0
- package/dist/error-handling-middleware.d.ts +3 -0
- package/dist/error-handling-middleware.d.ts.map +1 -0
- package/dist/error-handling-middleware.js +34 -0
- package/dist/error-handling-middleware.js.map +1 -0
- package/dist/handlers/auth0-handlers.d.ts.map +1 -1
- package/dist/handlers/auth0-handlers.js +34 -83
- package/dist/handlers/auth0-handlers.js.map +1 -1
- package/dist/handlers/login-redirect.d.ts.map +1 -1
- package/dist/handlers/login-redirect.js +3 -3
- package/dist/handlers/login-redirect.js.map +1 -1
- package/dist/handlers/oauth-handlers.d.ts +36 -0
- package/dist/handlers/oauth-handlers.d.ts.map +1 -0
- package/dist/handlers/oauth-handlers.js +116 -0
- package/dist/handlers/oauth-handlers.js.map +1 -0
- package/dist/handlers/utils.d.ts +11 -0
- package/dist/handlers/utils.d.ts.map +1 -0
- package/dist/handlers/utils.js +28 -0
- package/dist/handlers/utils.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/rules/rules-runner.d.ts.map +1 -1
- package/dist/rules/rules-runner.js +42 -28
- package/dist/rules/rules-runner.js.map +1 -1
- package/dist/rules/types.d.ts +12 -0
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/types.d.ts +29 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -4
- package/dist/types.js.map +1 -1
- package/dist/views/login.d.ts +3 -2
- package/dist/views/login.d.ts.map +1 -1
- package/dist/views/login.js +5 -4
- package/dist/views/login.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## \[0.8.2]
|
|
4
|
+
|
|
5
|
+
- Added specific support for the `grant_type` `client_credentials` which is required for machine-to-machine tokens. This grant_type specifically does not run the rules. The `scope` option now accepts an array of objects to specify specific scopes for specific clients.
|
|
6
|
+
- [4ffde63](https://github.com/thefrontside/simulacrum/commit/4ffde63842c0984f7bf5d6b3bd0f3d98ad938799) support client_credentials grant_type on 2022-11-17
|
|
7
|
+
- [9bb1b43](https://github.com/thefrontside/simulacrum/commit/9bb1b43bb80332e5357123550d72eef8681ae416) update change file with note about scope adjustments on 2022-11-23
|
|
8
|
+
- Tweaks the login form so the button is a true form submission button. This allows the form to input validate, and enables all form submission options (enter primarily the addition).
|
|
9
|
+
- [fa4a9e2](https://github.com/thefrontside/simulacrum/commit/fa4a9e27f72b6609419ee93d3c55b620a5feb6bc) auth0 submit as form button on 2022-11-21
|
|
10
|
+
- The simulator should consider the audience and client_id passed in the request. The values may be important for logic in user defined rules, and is used in validating the token, e.g. in `auth0-react`.
|
|
11
|
+
- [86cd7d0](https://github.com/thefrontside/simulacrum/commit/86cd7d06d5747c81d31a241726999955425a8e65) consider client_id and audience in auth0 sim request on 2022-11-16
|
|
12
|
+
|
|
13
|
+
## \[0.8.1]
|
|
14
|
+
|
|
15
|
+
- Async rules were not properly processing and would run as a race condition mutating the `user` and `context` objects. This would mean part of the rule might be applied. This adds some additional wrappers in the rule running to properly handle and `await` on async code.
|
|
16
|
+
- [013b5db](https://github.com/thefrontside/simulacrum/commit/013b5dbf12d1995efe1fb6fba90b55d3fe05f523) change file on 2022-11-03
|
|
17
|
+
|
|
3
18
|
## \[0.8.0]
|
|
4
19
|
|
|
5
20
|
- export `createAuth0Server` operation for running Auth0 server standalone.
|
package/README.md
CHANGED
|
@@ -229,6 +229,8 @@ let simulation = yield client.createSimulation("auth0", {
|
|
|
229
229
|
|
|
230
230
|
The `options` field supports the [auth0 configuration fields](https://auth0.com/docs/quickstart/spa/vanillajs#configure-auth0). The option fields should match the fields in the client application that is calling the auth0 server.
|
|
231
231
|
|
|
232
|
+
The `scope` also accepts an array of objects containing `clientID`, `scope` and optionally `audience` to enable dynamic scopes from a single simulator. This should allow multiple clients to all use the same simulator. Additionally, setting the `clientID: "default"` will enable a default fallback scope so every client does not need to be included.
|
|
233
|
+
|
|
232
234
|
An optional [`rulesDirectory` field](#rules) can specify a directory of [auth0 rules](https://auth0.com/docs/rules) code files, more on this [below](#rules).
|
|
233
235
|
|
|
234
236
|
### Services
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling-middleware.d.ts","sourceRoot":"","sources":["../src/error-handling-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,QA8BjG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultErrorHandler = void 0;
|
|
4
|
+
function defaultErrorHandler(error, _req, res, next) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (res.headersSent) {
|
|
7
|
+
return next(error);
|
|
8
|
+
}
|
|
9
|
+
let assertCondition = 'Assert condition failed: ';
|
|
10
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.startsWith(assertCondition)) {
|
|
11
|
+
let errorCode = 500;
|
|
12
|
+
let errorResponse = error.message;
|
|
13
|
+
if (error.message.includes('::')) {
|
|
14
|
+
let errorMessage = error.message.slice(assertCondition.length);
|
|
15
|
+
errorCode = parseInt(errorMessage.slice(0, 3));
|
|
16
|
+
errorResponse = errorMessage.slice(5);
|
|
17
|
+
}
|
|
18
|
+
res.status(errorCode).send(errorResponse);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.error(error);
|
|
22
|
+
res
|
|
23
|
+
.status(500)
|
|
24
|
+
.json({
|
|
25
|
+
error: {
|
|
26
|
+
name: error.name,
|
|
27
|
+
message: error.message,
|
|
28
|
+
stack: error.stack,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.defaultErrorHandler = defaultErrorHandler;
|
|
34
|
+
//# sourceMappingURL=error-handling-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling-middleware.js","sourceRoot":"","sources":["../src/error-handling-middleware.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CAAC,KAAY,EAAE,IAAa,EAAE,GAAa,EAAE,IAAkB;;IAChG,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;KACpB;IAED,IAAI,eAAe,GAAG,2BAA2B,CAAC;IAElD,IAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,0CAAE,UAAU,CAAC,eAAe,CAAC,EAAE;QAC/C,IAAI,SAAS,GAAG,GAAG,CAAC;QACpB,IAAI,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC;QAElC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAChC,IAAI,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAC/D,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvC;QAED,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAC3C;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,GAAG;aACA,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC;YACJ,KAAK,EAAE;gBACL,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB;SACF,CAAC,CAAC;KACN;AACH,CAAC;AA9BD,kDA8BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth0-handlers.d.ts","sourceRoot":"","sources":["../../src/handlers/auth0-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"auth0-handlers.d.ts","sourceRoot":"","sources":["../../src/handlers/auth0-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAA8B,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAY9C,oBAAY,MAAM,GACd,YAAY,GACZ,YAAY,GACZ,QAAQ,GACR,yBAAyB,GACzB,iBAAiB,GACjB,cAAc,GACd,YAAY,GACZ,WAAW,CAAA;AAEf,oBAAY,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC;IAChC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CAChD;AAED,eAAO,MAAM,mBAAmB,UAAW,UAAU,UAAU,SAAS,MAAM,CAAC,cAAc,MAAM,GAAG,WAAW,kBAAkB,KAAG,OAAO,MAAM,EAAE,cAAc,CAsLlK,CAAC"}
|
|
@@ -4,21 +4,16 @@ exports.createAuth0Handlers = void 0;
|
|
|
4
4
|
const login_redirect_1 = require("./login-redirect");
|
|
5
5
|
const web_message_1 = require("./web-message");
|
|
6
6
|
const login_1 = require("../views/login");
|
|
7
|
+
const oauth_handlers_1 = require("./oauth-handlers");
|
|
7
8
|
const assert_ts_1 = require("assert-ts");
|
|
8
9
|
const querystring_1 = require("querystring");
|
|
9
10
|
const base64_url_1 = require("base64-url");
|
|
10
11
|
const username_password_1 = require("../views/username-password");
|
|
11
|
-
const date_1 = require("../auth/date");
|
|
12
|
-
const jwt_1 = require("../auth/jwt");
|
|
13
|
-
const rules_runner_1 = require("../rules/rules-runner");
|
|
14
12
|
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
15
|
-
const
|
|
16
|
-
return [...people].find(predicate);
|
|
17
|
-
};
|
|
13
|
+
const utils_1 = require("./utils");
|
|
18
14
|
const createAuth0Handlers = (store, people, serviceURL, options) => {
|
|
19
15
|
let { audience, scope, clientID, rulesDirectory } = options;
|
|
20
|
-
let personQuery = createPersonQuery(people);
|
|
21
|
-
let rulesRunner = (0, rules_runner_1.createRulesRunner)(rulesDirectory);
|
|
16
|
+
let personQuery = (0, utils_1.createPersonQuery)(people);
|
|
22
17
|
let authorizeHandlers = {
|
|
23
18
|
query: (0, login_redirect_1.createLoginRedirectHandler)(options),
|
|
24
19
|
web_message: (0, web_message_1.createWebMessageHandler)()
|
|
@@ -43,14 +38,17 @@ const createAuth0Handlers = (store, people, serviceURL, options) => {
|
|
|
43
38
|
handler(req, res, next);
|
|
44
39
|
},
|
|
45
40
|
['/login']: function (req, res) {
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
var _a, _b;
|
|
42
|
+
let query = req.query;
|
|
43
|
+
let responseClientId = (_a = query.client_id) !== null && _a !== void 0 ? _a : clientID;
|
|
44
|
+
let responseAudience = (_b = query.audience) !== null && _b !== void 0 ? _b : audience;
|
|
45
|
+
(0, assert_ts_1.assert)(!!responseClientId, `no clientID assigned`);
|
|
48
46
|
let html = (0, login_1.loginView)({
|
|
49
47
|
domain: serviceURL().host,
|
|
50
48
|
scope,
|
|
51
|
-
redirectUri: redirect_uri,
|
|
52
|
-
clientID,
|
|
53
|
-
audience,
|
|
49
|
+
redirectUri: query.redirect_uri,
|
|
50
|
+
clientID: responseClientId,
|
|
51
|
+
audience: responseAudience,
|
|
54
52
|
loginFailed: false
|
|
55
53
|
});
|
|
56
54
|
res.set("Content-Type", "text/html");
|
|
@@ -90,78 +88,31 @@ const createAuth0Handlers = (store, people, serviceURL, options) => {
|
|
|
90
88
|
let routerUrl = `${redirect_uri}?${qs}`;
|
|
91
89
|
res.status(302).redirect(routerUrl);
|
|
92
90
|
},
|
|
93
|
-
['/oauth/token']: function (req, res) {
|
|
94
|
-
var _a, _b, _c, _d
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
res.status(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let valid = person.email.toLowerCase() === username.toLowerCase();
|
|
115
|
-
if (typeof password === 'undefined') {
|
|
116
|
-
return valid;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return valid && password === person.password;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
if (!user) {
|
|
123
|
-
res.status(401).send('Unauthorized');
|
|
124
|
-
return;
|
|
91
|
+
['/oauth/token']: async function (req, res, next) {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
try {
|
|
94
|
+
let iss = serviceURL().toString();
|
|
95
|
+
let responseClientId = (_b = (_a = req === null || req === void 0 ? void 0 : req.body) === null || _a === void 0 ? void 0 : _a.client_id) !== null && _b !== void 0 ? _b : clientID;
|
|
96
|
+
let responseAudience = (_d = (_c = req === null || req === void 0 ? void 0 : req.body) === null || _c === void 0 ? void 0 : _c.audience) !== null && _d !== void 0 ? _d : audience;
|
|
97
|
+
(0, assert_ts_1.assert)(!!responseClientId, '500::no clientID in options or request body');
|
|
98
|
+
let tokens = await (0, oauth_handlers_1.createTokens)({
|
|
99
|
+
body: req.body,
|
|
100
|
+
iss,
|
|
101
|
+
clientID: responseClientId,
|
|
102
|
+
audience: responseAudience,
|
|
103
|
+
rulesDirectory,
|
|
104
|
+
people,
|
|
105
|
+
scope
|
|
106
|
+
});
|
|
107
|
+
res.status(200).json({
|
|
108
|
+
...tokens,
|
|
109
|
+
expires_in: 86400,
|
|
110
|
+
token_type: "Bearer",
|
|
111
|
+
});
|
|
125
112
|
}
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
alg: "RS256",
|
|
129
|
-
typ: "JWT",
|
|
130
|
-
iss: serviceURL().toString(),
|
|
131
|
-
exp: (0, date_1.expiresAt)(),
|
|
132
|
-
iat: (0, date_1.epochTime)(),
|
|
133
|
-
email: username,
|
|
134
|
-
aud: clientID,
|
|
135
|
-
sub: user.id,
|
|
136
|
-
};
|
|
137
|
-
if (typeof nonce !== 'undefined') {
|
|
138
|
-
idTokenData.nonce = nonce;
|
|
113
|
+
catch (error) {
|
|
114
|
+
next(error);
|
|
139
115
|
}
|
|
140
|
-
let userData = {
|
|
141
|
-
name: (_a = req === null || req === void 0 ? void 0 : req.body) === null || _a === void 0 ? void 0 : _a.name,
|
|
142
|
-
email: (_b = req === null || req === void 0 ? void 0 : req.body) === null || _b === void 0 ? void 0 : _b.email,
|
|
143
|
-
user_id: (_c = req === null || req === void 0 ? void 0 : req.body) === null || _c === void 0 ? void 0 : _c.id,
|
|
144
|
-
nickname: (_d = req === null || req === void 0 ? void 0 : req.body) === null || _d === void 0 ? void 0 : _d.nickname,
|
|
145
|
-
picture: (_e = req === null || req === void 0 ? void 0 : req.body) === null || _e === void 0 ? void 0 : _e.picture,
|
|
146
|
-
identities: (_f = req === null || req === void 0 ? void 0 : req.body) === null || _f === void 0 ? void 0 : _f.identities,
|
|
147
|
-
};
|
|
148
|
-
let context = { clientID, accessToken: { scope }, idToken: idTokenData };
|
|
149
|
-
rulesRunner(userData, context);
|
|
150
|
-
let idToken = (0, jwt_1.createJsonWebToken)({ ...userData, ...context.idToken });
|
|
151
|
-
let accessToken = {
|
|
152
|
-
aud: audience,
|
|
153
|
-
sub: idTokenData.sub,
|
|
154
|
-
iat: (0, date_1.epochTime)(),
|
|
155
|
-
iss: idTokenData.iss,
|
|
156
|
-
exp: idTokenData.exp,
|
|
157
|
-
...context.accessToken
|
|
158
|
-
};
|
|
159
|
-
res.status(200).json({
|
|
160
|
-
access_token: (0, jwt_1.createJsonWebToken)(accessToken),
|
|
161
|
-
id_token: idToken,
|
|
162
|
-
expires_in: 86400,
|
|
163
|
-
token_type: "Bearer",
|
|
164
|
-
});
|
|
165
116
|
},
|
|
166
117
|
['/v2/logout']: function (req, res) {
|
|
167
118
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth0-handlers.js","sourceRoot":"","sources":["../../src/handlers/auth0-handlers.ts"],"names":[],"mappings":";;;AAGA,qDAA8D;AAC9D,+CAAwD;AACxD,0CAA2C;AAC3C,yCAAmC;AACnC,6CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"auth0-handlers.js","sourceRoot":"","sources":["../../src/handlers/auth0-handlers.ts"],"names":[],"mappings":";;;AAGA,qDAA8D;AAC9D,+CAAwD;AACxD,0CAA2C;AAC3C,qDAAgD;AAChD,yCAAmC;AACnC,6CAAwC;AACxC,2CAAoC;AACpC,kEAAkE;AAClE,+CAAqD;AACrD,mCAA4C;AAmBrC,MAAM,mBAAmB,GAAG,CAAC,KAAiB,EAAE,MAAwB,EAAE,UAAqB,EAAE,OAA2B,EAAkC,EAAE;IACrK,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAC5D,IAAI,WAAW,GAAG,IAAA,y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AAc,EAAE,IAAI;gBACpB,MAAM,EAAE,IAAI;gBACZ,EAAE,EAAE,UAAU;aACf,CAAC;YAEF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAtLW,QAAA,mBAAmB,uBAsL9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-redirect.d.ts","sourceRoot":"","sources":["../../src/handlers/login-redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,UAAU,CAAC;AAGhE,eAAO,MAAM,0BAA0B,YAAa,kBAAkB,KAAG,
|
|
1
|
+
{"version":3,"file":"login-redirect.d.ts","sourceRoot":"","sources":["../../src/handlers/login-redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,UAAU,CAAC;AAGhE,eAAO,MAAM,0BAA0B,YAAa,kBAAkB,KAAG,cAgCtE,CAAC"}
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createLoginRedirectHandler = void 0;
|
|
4
4
|
const querystring_1 = require("querystring");
|
|
5
5
|
const createLoginRedirectHandler = (options) => function loginRedirect(req, res) {
|
|
6
|
-
let { client_id, redirect_uri, scope, state, nonce, response_mode, code_challenge, code_challenge_method, auth0Client, response_type, } = req.query;
|
|
6
|
+
let { client_id, audience, redirect_uri, scope, state, nonce, response_mode, code_challenge, code_challenge_method, auth0Client, response_type, } = req.query;
|
|
7
7
|
res.status(302).redirect(`/login?${(0, querystring_1.stringify)({
|
|
8
8
|
state,
|
|
9
9
|
redirect_uri,
|
|
10
|
-
client: client_id,
|
|
10
|
+
client: client_id || options.clientID,
|
|
11
11
|
protocol: "oauth2",
|
|
12
12
|
scope,
|
|
13
13
|
response_type,
|
|
@@ -16,7 +16,7 @@ const createLoginRedirectHandler = (options) => function loginRedirect(req, res)
|
|
|
16
16
|
code_challenge,
|
|
17
17
|
code_challenge_method,
|
|
18
18
|
auth0Client,
|
|
19
|
-
audience: options.audience,
|
|
19
|
+
audience: audience || options.audience,
|
|
20
20
|
})}`);
|
|
21
21
|
};
|
|
22
22
|
exports.createLoginRedirectHandler = createLoginRedirectHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-redirect.js","sourceRoot":"","sources":["../../src/handlers/login-redirect.ts"],"names":[],"mappings":";;;AAEA,6CAAwC;AAEjC,MAAM,0BAA0B,GAAG,CAAC,OAA2B,EAAkB,EAAE,CACxF,SAAS,aAAa,CAAE,GAAY,EAAE,GAAa;IACjD,IAAI,EACF,SAAS,EACT,YAAY,EACZ,KAAK,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,GACd,GAAG,GAAG,CAAC,KAAoB,CAAC;IAE7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CACtB,UAAU,IAAA,uBAAS,EAAC;QAClB,KAAK;QACL,YAAY;QACZ,MAAM,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"login-redirect.js","sourceRoot":"","sources":["../../src/handlers/login-redirect.ts"],"names":[],"mappings":";;;AAEA,6CAAwC;AAEjC,MAAM,0BAA0B,GAAG,CAAC,OAA2B,EAAkB,EAAE,CACxF,SAAS,aAAa,CAAE,GAAY,EAAE,GAAa;IACjD,IAAI,EACF,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,GACd,GAAG,GAAG,CAAC,KAAoB,CAAC;IAE7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CACtB,UAAU,IAAA,uBAAS,EAAC;QAClB,KAAK;QACL,YAAY;QACZ,MAAM,EAAE,SAAS,IAAI,OAAO,CAAC,QAAQ;QACrC,QAAQ,EAAE,QAAQ;QAClB,KAAK;QACL,aAAa;QACb,aAAa;QACb,KAAK;QACL,cAAc;QACd,qBAAqB;QACrB,WAAW;QACX,QAAQ,EAAE,QAAQ,IAAI,OAAO,CAAC,QAAQ;KACvC,CAAC,EAAE,CACL,CAAC;AACJ,CAAC,CAAC;AAhCS,QAAA,0BAA0B,8BAgCnC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import type { Person } from '@simulacrum/server';
|
|
3
|
+
import type { RuleUser } from '../rules/types';
|
|
4
|
+
import type { ScopeConfig, AccessTokenPayload, IdTokenData } from '../types';
|
|
5
|
+
export declare const createTokens: ({ body, iss, clientID, audience, rulesDirectory, people, scope: scopeConfig, }: {
|
|
6
|
+
body: Request['body'];
|
|
7
|
+
iss: string;
|
|
8
|
+
clientID: string;
|
|
9
|
+
audience: string;
|
|
10
|
+
rulesDirectory: string | undefined;
|
|
11
|
+
people: Iterable<Person>;
|
|
12
|
+
scope: ScopeConfig;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
access_token: string;
|
|
15
|
+
id_token?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
access_token: string;
|
|
18
|
+
id_token: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const getIdToken: ({ body, iss, user, clientID, nonce, }: {
|
|
21
|
+
body: Request['body'];
|
|
22
|
+
iss: string;
|
|
23
|
+
user: Person;
|
|
24
|
+
clientID: string;
|
|
25
|
+
nonce: string | undefined;
|
|
26
|
+
}) => {
|
|
27
|
+
userData: RuleUser;
|
|
28
|
+
idTokenData: IdTokenData;
|
|
29
|
+
};
|
|
30
|
+
export declare const getBaseAccessToken: ({ iss, grant_type, scope, audience, }: {
|
|
31
|
+
iss: string;
|
|
32
|
+
grant_type: string;
|
|
33
|
+
scope: string;
|
|
34
|
+
audience: string;
|
|
35
|
+
}) => Partial<AccessTokenPayload>;
|
|
36
|
+
//# sourceMappingURL=oauth-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-handlers.d.ts","sourceRoot":"","sources":["../../src/handlers/oauth-handlers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAElB,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,YAAY;UASjB,OAAO,CAAC,MAAM,CAAC;SAChB,MAAM;cACD,MAAM;cACN,MAAM;oBACA,MAAM,GAAG,SAAS;YAC1B,SAAS,MAAM,CAAC;WACjB,WAAW;;;;;;;EA2CnB,CAAC;AAEF,eAAO,MAAM,UAAU;UAOf,OAAO,CAAC,MAAM,CAAC;SAChB,MAAM;UACL,MAAM;cACF,MAAM;WACT,MAAM,GAAG,SAAS;;;;CA4B1B,CAAC;AAEF,eAAO,MAAM,kBAAkB;SAMxB,MAAM;gBACC,MAAM;WACX,MAAM;cACH,MAAM;MACd,QAAQ,kBAAkB,CAO5B,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBaseAccessToken = exports.getIdToken = exports.createTokens = void 0;
|
|
4
|
+
const assert_ts_1 = require("assert-ts");
|
|
5
|
+
const base64_url_1 = require("base64-url");
|
|
6
|
+
const date_1 = require("../auth/date");
|
|
7
|
+
const jwt_1 = require("../auth/jwt");
|
|
8
|
+
const rules_runner_1 = require("../rules/rules-runner");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const createTokens = async ({ body, iss, clientID, audience, rulesDirectory, people, scope: scopeConfig, }) => {
|
|
11
|
+
let { grant_type } = body;
|
|
12
|
+
let scope = (0, utils_1.deriveScope)({ scopeConfig, clientID, audience });
|
|
13
|
+
let accessToken = (0, exports.getBaseAccessToken)({ iss, grant_type, scope, audience });
|
|
14
|
+
if (grant_type === 'client_credentials') {
|
|
15
|
+
return { access_token: (0, jwt_1.createJsonWebToken)(accessToken) };
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
let { user, nonce } = verifyUserExistsInStore({
|
|
19
|
+
people,
|
|
20
|
+
body,
|
|
21
|
+
grant_type,
|
|
22
|
+
});
|
|
23
|
+
let { idTokenData, userData } = (0, exports.getIdToken)({
|
|
24
|
+
body,
|
|
25
|
+
iss,
|
|
26
|
+
user,
|
|
27
|
+
clientID,
|
|
28
|
+
nonce,
|
|
29
|
+
});
|
|
30
|
+
let context = {
|
|
31
|
+
clientID,
|
|
32
|
+
accessToken: { scope, sub: idTokenData.sub },
|
|
33
|
+
idToken: idTokenData,
|
|
34
|
+
};
|
|
35
|
+
let rulesRunner = (0, rules_runner_1.createRulesRunner)(rulesDirectory);
|
|
36
|
+
// the rules mutate the values
|
|
37
|
+
await rulesRunner(userData, context);
|
|
38
|
+
return {
|
|
39
|
+
access_token: (0, jwt_1.createJsonWebToken)({
|
|
40
|
+
...accessToken,
|
|
41
|
+
...context.accessToken,
|
|
42
|
+
}),
|
|
43
|
+
id_token: (0, jwt_1.createJsonWebToken)({
|
|
44
|
+
...userData,
|
|
45
|
+
...context.idToken,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.createTokens = createTokens;
|
|
51
|
+
const getIdToken = ({ body, iss, user, clientID, nonce, }) => {
|
|
52
|
+
let userData = {
|
|
53
|
+
name: body === null || body === void 0 ? void 0 : body.name,
|
|
54
|
+
email: body === null || body === void 0 ? void 0 : body.email,
|
|
55
|
+
user_id: body === null || body === void 0 ? void 0 : body.id,
|
|
56
|
+
nickname: body === null || body === void 0 ? void 0 : body.nickname,
|
|
57
|
+
picture: body === null || body === void 0 ? void 0 : body.picture,
|
|
58
|
+
identities: body === null || body === void 0 ? void 0 : body.identities,
|
|
59
|
+
};
|
|
60
|
+
(0, assert_ts_1.assert)(!!user.email, '500::User in store requires an email');
|
|
61
|
+
let idTokenData = {
|
|
62
|
+
alg: 'RS256',
|
|
63
|
+
typ: 'JWT',
|
|
64
|
+
iss,
|
|
65
|
+
exp: (0, date_1.expiresAt)(),
|
|
66
|
+
iat: (0, date_1.epochTime)(),
|
|
67
|
+
email: user.email,
|
|
68
|
+
aud: clientID,
|
|
69
|
+
sub: user.id,
|
|
70
|
+
};
|
|
71
|
+
if (typeof nonce !== 'undefined') {
|
|
72
|
+
idTokenData.nonce = nonce;
|
|
73
|
+
}
|
|
74
|
+
return { userData, idTokenData };
|
|
75
|
+
};
|
|
76
|
+
exports.getIdToken = getIdToken;
|
|
77
|
+
const getBaseAccessToken = ({ iss, grant_type, scope, audience, }) => ({
|
|
78
|
+
iss,
|
|
79
|
+
exp: (0, date_1.expiresAt)(),
|
|
80
|
+
iat: (0, date_1.epochTime)(),
|
|
81
|
+
aud: audience,
|
|
82
|
+
gty: grant_type,
|
|
83
|
+
scope,
|
|
84
|
+
});
|
|
85
|
+
exports.getBaseAccessToken = getBaseAccessToken;
|
|
86
|
+
const verifyUserExistsInStore = ({ people, body, grant_type, }) => {
|
|
87
|
+
let { code } = body;
|
|
88
|
+
let personQuery = (0, utils_1.createPersonQuery)(people);
|
|
89
|
+
let nonce;
|
|
90
|
+
let username;
|
|
91
|
+
let password;
|
|
92
|
+
if (grant_type === 'password') {
|
|
93
|
+
username = body.username;
|
|
94
|
+
password = body.password;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// specifically grant_type === 'authorization_code'
|
|
98
|
+
// but naively using it to handle other cases at the moment
|
|
99
|
+
(0, assert_ts_1.assert)(typeof code !== 'undefined', '400::no code in /oauth/token');
|
|
100
|
+
[nonce, username] = (0, base64_url_1.decode)(code).split(':');
|
|
101
|
+
}
|
|
102
|
+
(0, assert_ts_1.assert)(!!username, `400::no nonce in store for ${code}`);
|
|
103
|
+
let user = personQuery((person) => {
|
|
104
|
+
(0, assert_ts_1.assert)(!!person.email, `500::no email defined on person scenario`);
|
|
105
|
+
let valid = person.email.toLowerCase() === username.toLowerCase();
|
|
106
|
+
if (typeof password === 'undefined') {
|
|
107
|
+
return valid;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return valid && password === person.password;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
(0, assert_ts_1.assert)(!!user, '401::Unauthorized');
|
|
114
|
+
return { user, nonce };
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=oauth-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-handlers.js","sourceRoot":"","sources":["../../src/handlers/oauth-handlers.ts"],"names":[],"mappings":";;;AAAA,yCAAmC;AACnC,2CAAoD;AACpD,uCAAoD;AACpD,qCAAiD;AACjD,wDAA0D;AAC1D,mCAAyD;AAYlD,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,MAAM,EACN,KAAK,EAAE,WAAW,GASnB,EAAE,EAAE;IACH,IAAI,EAAE,UAAU,EAAE,GAA8B,IAAI,CAAC;IACrD,IAAI,KAAK,GAAG,IAAA,mBAAW,EAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE7D,IAAI,WAAW,GAAG,IAAA,0BAAkB,EAAC,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC3E,IAAI,UAAU,KAAK,oBAAoB,EAAE;QACvC,OAAO,EAAE,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CAAC;IAC9B,IAAI,QAAgB,CAAC;IACrB,IAAI,QAA4B,CAAC;IAEjC,IAAI,UAAU,KAAK,UAAU,EAAE;QAC7B,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QACzB,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;KAC1B;SAAM;QACL,mDAAmD;QACnD,2DAA2D;QAC3D,IAAA,kBAAM,EAAC,OAAO,IAAI,KAAK,WAAW,EAAE,8BAA8B,CAAC,CAAC;QACpE,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,mBAAY,EAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACnD;IAED,IAAA,kBAAM,EAAC,CAAC,CAAC,QAAQ,EAAE,8BAA8B,IAAI,EAAE,CAAC,CAAC;IAEzD,IAAI,IAAI,GAAuB,WAAW,CAAC,CAAC,MAAM,EAAE,EAAE;QACpD,IAAA,kBAAM,EAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,0CAA0C,CAAC,CAAC;QAEnE,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;QAElE,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;aAAM;YACL,OAAO,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC;SAC9C;IACH,CAAC,CAAC,CAAC;IAEH,IAAA,kBAAM,EAAC,CAAC,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAEpC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Person } from '@simulacrum/server';
|
|
2
|
+
import type { ScopeConfig } from '../types';
|
|
3
|
+
declare type Predicate<T> = (this: void, value: T, index: number, obj: T[]) => boolean;
|
|
4
|
+
export declare const createPersonQuery: (people: Iterable<Person>) => (predicate: Predicate<Person>) => Person | undefined;
|
|
5
|
+
export declare const deriveScope: ({ scopeConfig, clientID, audience, }: {
|
|
6
|
+
scopeConfig: ScopeConfig;
|
|
7
|
+
clientID: string;
|
|
8
|
+
audience: string;
|
|
9
|
+
}) => string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/handlers/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,aAAK,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC;AAE/E,eAAO,MAAM,iBAAiB,WACnB,SAAS,MAAM,CAAC,iBAAiB,UAAU,MAAM,CAAC,uBAE1D,CAAC;AAEJ,eAAO,MAAM,WAAW;iBAKT,WAAW;cACd,MAAM;cACN,MAAM;YAwCjB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveScope = exports.createPersonQuery = void 0;
|
|
4
|
+
const assert_ts_1 = require("assert-ts");
|
|
5
|
+
const createPersonQuery = (people) => (predicate) => {
|
|
6
|
+
return [...people].find(predicate);
|
|
7
|
+
};
|
|
8
|
+
exports.createPersonQuery = createPersonQuery;
|
|
9
|
+
const deriveScope = ({ scopeConfig, clientID, audience, }) => {
|
|
10
|
+
if (typeof scopeConfig === 'string')
|
|
11
|
+
return scopeConfig;
|
|
12
|
+
let defaultScope = scopeConfig.find((application) => application.clientID === 'default');
|
|
13
|
+
(0, assert_ts_1.assert)(!!clientID, `500::Did not have a clientID to derive the scope`);
|
|
14
|
+
let application = scopeConfig.find((application) => application.clientID === clientID &&
|
|
15
|
+
(application.audience ? application.audience === audience : true));
|
|
16
|
+
if (!application) {
|
|
17
|
+
let ignoreAudience = scopeConfig.find((application) => application.clientID === clientID);
|
|
18
|
+
(0, assert_ts_1.assert)(ignoreAudience === undefined, `500::Found application matching clientID, ${ignoreAudience === null || ignoreAudience === void 0 ? void 0 : ignoreAudience.clientID}, but incorrect audience, configured: ${ignoreAudience === null || ignoreAudience === void 0 ? void 0 : ignoreAudience.audience} :: passed: ${audience}`);
|
|
19
|
+
}
|
|
20
|
+
if (!application && defaultScope) {
|
|
21
|
+
application = defaultScope;
|
|
22
|
+
}
|
|
23
|
+
(0, assert_ts_1.assert)(!!application, `500::Could not find application with clientID: ${clientID}`);
|
|
24
|
+
(0, assert_ts_1.assert)(!!application.scope, `500::${application.clientID} is expected to have a scope`);
|
|
25
|
+
return application.scope;
|
|
26
|
+
};
|
|
27
|
+
exports.deriveScope = deriveScope;
|
|
28
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handlers/utils.ts"],"names":[],"mappings":";;;AAAA,yCAAmC;AAM5B,MAAM,iBAAiB,GAC5B,CAAC,MAAwB,EAAE,EAAE,CAAC,CAAC,SAA4B,EAAE,EAAE;IAC7D,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC,CAAC;AAHS,QAAA,iBAAiB,qBAG1B;AAEG,MAAM,WAAW,GAAG,CAAC,EAC1B,WAAW,EACX,QAAQ,EACR,QAAQ,GAKT,EAAE,EAAE;IACH,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAC;IACxD,IAAI,YAAY,GAAG,WAAW,CAAC,IAAI,CACjC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,KAAK,SAAS,CACpD,CAAC;IAEF,IAAA,kBAAM,EAAC,CAAC,CAAC,QAAQ,EAAE,kDAAkD,CAAC,CAAC;IAEvE,IAAI,WAAW,GAAG,WAAW,CAAC,IAAI,CAChC,CAAC,WAAW,EAAE,EAAE,CACd,WAAW,CAAC,QAAQ,KAAK,QAAQ;QACjC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CACpE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE;QAChB,IAAI,cAAc,GAAG,WAAW,CAAC,IAAI,CACnC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,KAAK,QAAQ,CACnD,CAAC;QACF,IAAA,kBAAM,EACJ,cAAc,KAAK,SAAS,EAC5B,6CAA6C,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,yCAAyC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,eAAe,QAAQ,EAAE,CAChK,CAAC;KACH;IAED,IAAI,CAAC,WAAW,IAAI,YAAY,EAAE;QAChC,WAAW,GAAG,YAAY,CAAC;KAC5B;IAED,IAAA,kBAAM,EACJ,CAAC,CAAC,WAAW,EACb,kDAAkD,QAAQ,EAAE,CAC7D,CAAC;IAEF,IAAA,kBAAM,EACJ,CAAC,CAAC,WAAW,CAAC,KAAK,EACnB,QAAQ,WAAW,CAAC,QAAQ,8BAA8B,CAC3D,CAAC;IAEF,OAAO,WAAW,CAAC,KAAK,CAAC;AAC3B,CAAC,CAAC;AA/CW,QAAA,WAAW,eA+CtB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Person, Simulator } from '@simulacrum/server';
|
|
2
|
-
import { Operation } from 'effection';
|
|
2
|
+
import type { Operation } from 'effection';
|
|
3
3
|
import type { Auth0Store } from './handlers/auth0-handlers';
|
|
4
4
|
import type { Auth0Configuration } from './types';
|
|
5
5
|
export { getConfig } from './config/get-config';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAErF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK3C,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,2BAA2B,CAAC;AAOzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIhD,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA4CD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS,CAAC,MAAM,CAAC,CAyChF;AAED,eAAO,MAAM,KAAK,EAAE,SAanB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const server_1 = require("@simulacrum/server");
|
|
|
27
27
|
const express_1 = __importStar(require("express"));
|
|
28
28
|
const path_1 = __importDefault(require("path"));
|
|
29
29
|
const get_config_1 = require("./config/get-config");
|
|
30
|
+
const error_handling_middleware_1 = require("./error-handling-middleware");
|
|
30
31
|
const auth0_handlers_1 = require("./handlers/auth0-handlers");
|
|
31
32
|
const get_service_url_1 = require("./handlers/get-service-url");
|
|
32
33
|
const openid_handlers_1 = require("./handlers/openid-handlers");
|
|
@@ -100,6 +101,8 @@ function createAuth0Server(options) {
|
|
|
100
101
|
if (debug) {
|
|
101
102
|
app.use(server_1.consoleLogger);
|
|
102
103
|
}
|
|
104
|
+
// needs to be the last middleware added
|
|
105
|
+
app.use(error_handling_middleware_1.defaultErrorHandler);
|
|
103
106
|
let server = yield (0, server_1.createServer)(app, { protocol: 'https', port });
|
|
104
107
|
return {
|
|
105
108
|
port: server.address.port
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAyE;AAEzE,mDAAoD;AACpD,gDAAwB;AACxB,oDAAgD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAyE;AAEzE,mDAAoD;AACpD,gDAAwB;AACxB,oDAAgD;AAChD,2EAAkE;AAElE,8DAAgE;AAChE,gEAA2D;AAC3D,gEAAkE;AAClE,0DAAsD;AACtD,oDAAgD;AAChD,kDAAqD;AAGrD,kDAAgD;AAAvC,uGAAA,SAAS,OAAA;AAElB,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAe1D,MAAM,kBAAkB,GAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACtE,IAAI,EAAE,cAAc;IACpB,CAAC,IAAI;QACH,IAAI,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,KA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Ac,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;iBAC3C,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;iBACpC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;iBACtC,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAC;iBAC/D,GAAG,CAAC,mCAAmC,EAAE,MAAM,CAAC,mCAAmC,CAAC,CAAC,CAAC;YAEzF,IAAI,KAAK,EAAE;gBACT,GAAG,CAAC,GAAG,CAAC,sBAAa,CAAC,CAAC;aACxB;YAED,wCAAwC;YACxC,GAAG,CAAC,GAAG,CAAC,+CAAmB,CAAC,CAAC;YAE7B,IAAI,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAElE,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;aAC1B,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAzCD,8CAyCC;AAEM,MAAM,KAAK,GAAc,GAAG,EAAE;IACnC,OAAO;QACL,QAAQ,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE;QACvC,SAAS,EAAE;YACT;;;;;eAKG;YACH,MAAM,EAAN,eAAM;SACP;KACF,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,KAAK,SAahB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules-runner.d.ts","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"rules-runner.d.ts","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAQ,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3D,oBAAY,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;AAoDrF,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAyBjE"}
|
|
@@ -9,21 +9,9 @@ const vm_1 = __importDefault(require("vm"));
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const assert_ts_1 = require("assert-ts");
|
|
11
11
|
const parse_rules_files_1 = require("./parse-rules-files");
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (typeof rulesPath === 'undefined') {
|
|
16
|
-
return callback;
|
|
17
|
-
}
|
|
18
|
-
let fullPath = path_1.default.join(process.cwd(), rulesPath);
|
|
19
|
-
(0, assert_ts_1.assert)(fs_1.default.existsSync(fullPath), `no rules directory at ${fullPath}`);
|
|
20
|
-
let rules = (0, parse_rules_files_1.parseRulesFiles)(rulesPath);
|
|
21
|
-
if (rules.length === 0) {
|
|
22
|
-
return callback;
|
|
23
|
-
}
|
|
24
|
-
return (user, context) => {
|
|
25
|
-
console.debug(`applying ${rules.length} rules`);
|
|
26
|
-
let vmContext = vm_1.default.createContext({
|
|
12
|
+
async function runRule(user, context, rule) {
|
|
13
|
+
await new Promise((resolve, reject) => {
|
|
14
|
+
let sandbox = {
|
|
27
15
|
process,
|
|
28
16
|
Buffer,
|
|
29
17
|
clearImmediate,
|
|
@@ -35,26 +23,52 @@ function createRulesRunner(rulesPath) {
|
|
|
35
23
|
console,
|
|
36
24
|
require,
|
|
37
25
|
module,
|
|
26
|
+
resolve,
|
|
27
|
+
reject,
|
|
38
28
|
__simulator: {
|
|
39
29
|
...{
|
|
40
30
|
user,
|
|
41
|
-
context: { ...context
|
|
42
|
-
callback,
|
|
31
|
+
context: { ...context },
|
|
43
32
|
},
|
|
44
33
|
},
|
|
34
|
+
};
|
|
35
|
+
let vmContext = vm_1.default.createContext(sandbox);
|
|
36
|
+
(0, assert_ts_1.assert)(typeof rule !== 'undefined', 'undefined rule');
|
|
37
|
+
let { code, filename } = rule;
|
|
38
|
+
console.debug(`executing rule ${path_1.default.basename(filename)}`);
|
|
39
|
+
let script = new vm_1.default.Script(`
|
|
40
|
+
(async function(exports) {
|
|
41
|
+
try {
|
|
42
|
+
await (${code})(__simulator.user, __simulator.context, resolve);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error(err);
|
|
45
|
+
reject();
|
|
46
|
+
}
|
|
47
|
+
})(module.exports)
|
|
48
|
+
`);
|
|
49
|
+
script.runInContext(vmContext, {
|
|
50
|
+
filename,
|
|
51
|
+
displayErrors: true,
|
|
52
|
+
timeout: 20000,
|
|
45
53
|
});
|
|
54
|
+
}).catch((error) => console.error(error));
|
|
55
|
+
}
|
|
56
|
+
function createRulesRunner(rulesPath) {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
+
let callback = (_user, _context) => { };
|
|
59
|
+
if (typeof rulesPath === 'undefined') {
|
|
60
|
+
return callback;
|
|
61
|
+
}
|
|
62
|
+
let fullPath = path_1.default.join(process.cwd(), rulesPath);
|
|
63
|
+
(0, assert_ts_1.assert)(fs_1.default.existsSync(fullPath), `no rules directory at ${fullPath}`);
|
|
64
|
+
let rules = (0, parse_rules_files_1.parseRulesFiles)(rulesPath);
|
|
65
|
+
if (rules.length === 0) {
|
|
66
|
+
return callback;
|
|
67
|
+
}
|
|
68
|
+
return async (user, context) => {
|
|
69
|
+
console.debug(`applying ${rules.length} rules`);
|
|
46
70
|
for (let rule of rules) {
|
|
47
|
-
(
|
|
48
|
-
let { code, filename } = rule;
|
|
49
|
-
console.debug(`executing rule ${path_1.default.basename(filename)}`);
|
|
50
|
-
let script = new vm_1.default.Script(`(function(exports) {
|
|
51
|
-
(${code})(__simulator.user, __simulator.context, __simulator.callback)
|
|
52
|
-
}
|
|
53
|
-
(module.exports));
|
|
54
|
-
`);
|
|
55
|
-
script.runInContext(vmContext, {
|
|
56
|
-
filename,
|
|
57
|
-
});
|
|
71
|
+
await runRule(user, context, rule);
|
|
58
72
|
}
|
|
59
73
|
};
|
|
60
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules-runner.js","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AACpB,4CAAoB;AACpB,yCAAmC;AACnC,2DAAsD;AAKtD,
|
|
1
|
+
{"version":3,"file":"rules-runner.js","sourceRoot":"","sources":["../../src/rules/rules-runner.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AACpB,4CAAoB;AACpB,yCAAmC;AACnC,2DAAsD;AAKtD,KAAK,UAAU,OAAO,CAAQ,IAAc,EAAE,OAA0B,EAAE,IAAU;IAClF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpC,IAAI,OAAO,GAAG;YACZ,OAAO;YACP,MAAM;YACN,cAAc;YACd,aAAa;YACb,YAAY;YACZ,YAAY;YACZ,WAAW;YACX,UAAU;YACV,OAAO;YACP,OAAO;YACP,MAAM;YACN,OAAO;YACP,MAAM;YACN,WAAW,EAAE;gBACX,GAAG;oBACD,IAAI;oBACJ,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE;iBACxB;aACF;SACF,CAAC;QAEF,IAAI,SAAS,GAAG,YAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAA,kBAAM,EAAC,OAAO,IAAI,KAAK,WAAW,EAAE,gBAAgB,CAAC,CAAC;QAEtD,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE9B,OAAO,CAAC,KAAK,CAAC,kBAAkB,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAE3D,IAAI,MAAM,GAAG,IAAI,YAAE,CAAC,MAAM,CAAC;;;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string | undefined;
|
|
15
15
|
name?: string | undefined;
|
|
16
|
+
identities: IdentityProvider[] | undefined;
|
|
16
17
|
}
|
|
18
|
+
declare type IdentityProvider = {
|
|
19
|
+
provider: string;
|
|
20
|
+
user_id: string;
|
|
21
|
+
connection: string;
|
|
22
|
+
isSocial: boolean;
|
|
23
|
+
};
|
|
17
24
|
export interface RuleContext<A, I> {
|
|
18
25
|
clientID: string;
|
|
19
26
|
accessToken: {
|
|
@@ -21,4 +28,9 @@ export interface RuleContext<A, I> {
|
|
|
21
28
|
} & A;
|
|
22
29
|
idToken: I;
|
|
23
30
|
}
|
|
31
|
+
export interface Rule {
|
|
32
|
+
code: string;
|
|
33
|
+
filename: string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
24
36
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rules/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,CAAC,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KAC1B,GAAG,CAAC,CAAC;IAEN,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,19 @@ export declare const configurationSchema: z.ZodObject<{
|
|
|
4
4
|
domain: z.ZodOptional<z.ZodString>;
|
|
5
5
|
audience: z.ZodOptional<z.ZodString>;
|
|
6
6
|
clientID: z.ZodOptional<z.ZodString>;
|
|
7
|
-
scope: z.ZodString
|
|
7
|
+
scope: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
|
|
8
|
+
clientID: z.ZodString;
|
|
9
|
+
audience: z.ZodOptional<z.ZodString>;
|
|
10
|
+
scope: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
audience?: string | undefined;
|
|
13
|
+
clientID: string;
|
|
14
|
+
scope: string;
|
|
15
|
+
}, {
|
|
16
|
+
audience?: string | undefined;
|
|
17
|
+
clientID: string;
|
|
18
|
+
scope: string;
|
|
19
|
+
}>, "many">]>;
|
|
8
20
|
clientSecret: z.ZodOptional<z.ZodString>;
|
|
9
21
|
rulesDirectory: z.ZodOptional<z.ZodString>;
|
|
10
22
|
auth0SessionCookieName: z.ZodOptional<z.ZodString>;
|
|
@@ -22,7 +34,11 @@ export declare const configurationSchema: z.ZodObject<{
|
|
|
22
34
|
auth0CookieSecret?: string | undefined;
|
|
23
35
|
connection?: string | undefined;
|
|
24
36
|
cookieSecret?: string | undefined;
|
|
25
|
-
scope: string
|
|
37
|
+
scope: string | {
|
|
38
|
+
audience?: string | undefined;
|
|
39
|
+
clientID: string;
|
|
40
|
+
scope: string;
|
|
41
|
+
}[];
|
|
26
42
|
}, {
|
|
27
43
|
port?: number | undefined;
|
|
28
44
|
domain?: string | undefined;
|
|
@@ -34,10 +50,20 @@ export declare const configurationSchema: z.ZodObject<{
|
|
|
34
50
|
auth0CookieSecret?: string | undefined;
|
|
35
51
|
connection?: string | undefined;
|
|
36
52
|
cookieSecret?: string | undefined;
|
|
37
|
-
scope: string
|
|
53
|
+
scope: string | {
|
|
54
|
+
audience?: string | undefined;
|
|
55
|
+
clientID: string;
|
|
56
|
+
scope: string;
|
|
57
|
+
}[];
|
|
38
58
|
}>;
|
|
39
59
|
export declare type Schema = z.infer<typeof configurationSchema>;
|
|
40
60
|
declare type ReadonlyFields = 'audience' | 'clientID' | 'scope' | 'port';
|
|
61
|
+
export declare type GrantType = 'password' | 'client_credentials' | 'authorization_code';
|
|
62
|
+
export declare type ScopeConfig = string | {
|
|
63
|
+
audience?: string;
|
|
64
|
+
clientID: string;
|
|
65
|
+
scope: string;
|
|
66
|
+
}[];
|
|
41
67
|
export declare type Auth0Configuration = Required<Pick<Schema, ReadonlyFields>> & Omit<Schema, ReadonlyFields>;
|
|
42
68
|
export declare type ResponseModes = 'query' | 'web_message';
|
|
43
69
|
export declare type QueryParams = {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwB9B,CAAC;AAEH,oBAAY,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEzD,aAAK,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAIjE,oBAAY,SAAS,GAAG,UAAU,GAAG,oB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AM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IAEd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,kBAAkB,CAAC;CAC7B"}
|
package/dist/types.js
CHANGED
|
@@ -4,11 +4,21 @@ exports.configurationSchema = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
// TODO: better validation
|
|
6
6
|
exports.configurationSchema = zod_1.z.object({
|
|
7
|
-
port: zod_1.z.optional(zod_1.z
|
|
7
|
+
port: zod_1.z.optional(zod_1.z
|
|
8
|
+
.number()
|
|
9
|
+
.gt(2999, 'port must be greater than 2999')
|
|
10
|
+
.lt(10000, 'must be less than 10000')),
|
|
8
11
|
domain: zod_1.z.optional(zod_1.z.string().min(1, 'domain is required')),
|
|
9
|
-
audience: zod_1.z.optional(zod_1.z.string().min(1,
|
|
10
|
-
clientID: zod_1.z.optional(zod_1.z.string().max(32,
|
|
11
|
-
scope: zod_1.z.
|
|
12
|
+
audience: zod_1.z.optional(zod_1.z.string().min(1, 'audience is required')),
|
|
13
|
+
clientID: zod_1.z.optional(zod_1.z.string().max(32, 'must be 32 characters long')),
|
|
14
|
+
scope: zod_1.z.union([
|
|
15
|
+
zod_1.z.string().min(1, 'scope is required'),
|
|
16
|
+
zod_1.z.array(zod_1.z.object({
|
|
17
|
+
clientID: zod_1.z.string().max(32, 'must be 32 characters long'),
|
|
18
|
+
audience: zod_1.z.optional(zod_1.z.string().min(1, 'audience is required')),
|
|
19
|
+
scope: zod_1.z.string().min(1, 'scope is required'),
|
|
20
|
+
}))
|
|
21
|
+
]),
|
|
12
22
|
clientSecret: zod_1.z.optional(zod_1.z.string()),
|
|
13
23
|
rulesDirectory: zod_1.z.optional(zod_1.z.string()),
|
|
14
24
|
auth0SessionCookieName: zod_1.z.optional(zod_1.z.string()),
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,0BAA0B;AACb,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,OAAC,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,0BAA0B;AACb,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,OAAC,CAAC,QAAQ,CACd,OAAC;SACE,MAAM,EAAE;SACR,EAAE,CAAC,IAAI,EAAE,gCAAgC,CAAC;SAC1C,EAAE,CAAC,KAAK,EAAE,yBAAyB,CAAC,CACxC;IACD,MAAM,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAC3D,QAAQ,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAC/D,QAAQ,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,4BAA4B,CAAC,CAAC;IACtE,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC;QACX,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,mBAAmB,CAAC;QACtC,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,CAAC;YACf,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,4BAA4B,CAAC;YAC1D,QAAQ,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;YAC/D,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,mBAAmB,CAAC;SAC9C,CAAC,CAAC;KACJ,CAAC;IACJ,YAAY,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IACpC,cAAc,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IACtC,sBAAsB,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IAC9C,iBAAiB,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IACzC,UAAU,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;IAClC,YAAY,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;CACrC,CAAC,CAAC"}
|
package/dist/views/login.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import type { ScopeConfig } from '../types';
|
|
1
2
|
interface LoginViewProps {
|
|
2
3
|
domain: string;
|
|
3
|
-
scope:
|
|
4
|
+
scope: ScopeConfig;
|
|
4
5
|
redirectUri: string;
|
|
5
6
|
clientID: string;
|
|
6
7
|
audience: string;
|
|
7
8
|
loginFailed: boolean;
|
|
8
9
|
}
|
|
9
|
-
export declare const loginView: ({ domain, scope, redirectUri, clientID, audience, loginFailed }: LoginViewProps) => string;
|
|
10
|
+
export declare const loginView: ({ domain, scope: scopeConfig, redirectUri, clientID, audience, loginFailed }: LoginViewProps) => string;
|
|
10
11
|
export {};
|
|
11
12
|
//# sourceMappingURL=login.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/views/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/views/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,WAAW,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,iFAOnB,cAAc,KAAG,MAwFnB,CAAC"}
|
package/dist/views/login.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loginView = void 0;
|
|
4
|
+
const utils_1 = require("../handlers/utils");
|
|
4
5
|
const html = String.raw;
|
|
5
|
-
const loginView = ({ domain, scope, redirectUri, clientID, audience, loginFailed = false }) => {
|
|
6
|
+
const loginView = ({ domain, scope: scopeConfig, redirectUri, clientID, audience, loginFailed = false }) => {
|
|
6
7
|
return html `
|
|
7
8
|
<html lang="en">
|
|
8
9
|
<head>
|
|
@@ -37,7 +38,7 @@ const loginView = ({ domain, scope, redirectUri, clientID, audience, loginFailed
|
|
|
37
38
|
<div class="error bg-red-500 text-white p-3 ${loginFailed ? '' : 'hidden'}">Wrong email or password</div>
|
|
38
39
|
|
|
39
40
|
<div>
|
|
40
|
-
<button id="submit" type="
|
|
41
|
+
<button id="submit" type="form" class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
41
42
|
<span class="absolute left-0 inset-y-0 flex items-center pl-3">
|
|
42
43
|
<svg class="h-5 w-5 text-blue-500 group-hover:text-blue-400" x-description="Heroicon name: solid/lock-closed" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
43
44
|
<path fill-rule="evenodd" d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z" clip-rule="evenodd"></path>
|
|
@@ -61,7 +62,7 @@ const loginView = ({ domain, scope, redirectUri, clientID, audience, loginFailed
|
|
|
61
62
|
var form = document.querySelector('#the-form');
|
|
62
63
|
var button = document.querySelector('#sumbit');
|
|
63
64
|
|
|
64
|
-
submit.addEventListener('
|
|
65
|
+
submit.addEventListener('submit', function(e) {
|
|
65
66
|
let params = new URLSearchParams(window.location.search);
|
|
66
67
|
|
|
67
68
|
var username = document.querySelector('#username');
|
|
@@ -72,7 +73,7 @@ const loginView = ({ domain, scope, redirectUri, clientID, audience, loginFailed
|
|
|
72
73
|
username: username.value,
|
|
73
74
|
password: password.value,
|
|
74
75
|
realm: 'Username-Password-Authentication',
|
|
75
|
-
scope: '${
|
|
76
|
+
scope: '${(0, utils_1.deriveScope)({ scopeConfig, clientID, audience })}',
|
|
76
77
|
nonce: params.get('nonce'),
|
|
77
78
|
state: params.get('state')
|
|
78
79
|
},
|
package/dist/views/login.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/views/login.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/views/login.ts"],"names":[],"mappings":";;;AACA,6CAAgD;AAChD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC;AAWjB,MAAM,SAAS,GAAG,CAAC,EACxB,MAAM,EACN,KAAK,EAAE,WAAW,EAClB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,WAAW,GAAG,KAAK,EACJ,EAAU,EAAE;IAC3B,OAAO,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;uHAwB0G,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE;;;;iIAIzB,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE;;;4DAGxG,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ;;;;;;;;;;;;;;;;;;yBAkB9D,MAAM;2BACJ,QAAQ;8BACL,WAAW;2BACd,QAAQ;;;;;;;;;;;;;;;;;4BAiBP,IAAA,mBAAW,EAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;;;;;;;;;;;;;;;;;GAiBzE,CAAC;AACJ,CAAC,CAAC;AA/FW,QAAA,SAAS,aA+FpB"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simulacrum/auth0-simulator",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Run local instance of Auth0 API for local development and integration testing",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "bin/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "rimraf *.tsbuildinfo dist",
|
|
9
|
-
"test": "NODE_EXTRA_CA_CERTS=\"$(mkcert -CAROOT)/rootCA.pem\" mocha -r ts-node/register --timeout
|
|
9
|
+
"test": "NODE_EXTRA_CA_CERTS=\"$(mkcert -CAROOT)/rootCA.pem\" mocha -r ts-node/register --timeout 21000 test/**/*.test.ts",
|
|
10
10
|
"prepack": "tsc --build tsconfig.dist.json && copy-cli \"./src/views/**/*.png\" ./dist/views/",
|
|
11
11
|
"build": "npm run prepack",
|
|
12
12
|
"lint": "eslint src bin test",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@effection/process": "^2.0.1",
|
|
42
42
|
"@simulacrum/client": "0.5.4",
|
|
43
|
-
"@simulacrum/server": "0.6.
|
|
43
|
+
"@simulacrum/server": "0.6.3",
|
|
44
44
|
"@types/faker": "^5.1.7",
|
|
45
45
|
"assert-ts": "^0.3.2",
|
|
46
46
|
"base64-url": "^2.3.3",
|