@logto/express 2.3.17 → 3.0.4
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/lib/index.js +9 -2
- package/lib/types.d.ts +2 -1
- package/package.json +5 -7
- package/lib/errors.cjs +0 -14
- package/lib/index.cjs +0 -122
- package/lib/storage.cjs +0 -24
package/lib/index.js
CHANGED
|
@@ -27,11 +27,18 @@ const handleAuthRoutes = (config) => {
|
|
|
27
27
|
const nodeClient = createNodeClient(request, response, config);
|
|
28
28
|
switch (action) {
|
|
29
29
|
case 'sign-in': {
|
|
30
|
-
await nodeClient.signIn(
|
|
30
|
+
await nodeClient.signIn({
|
|
31
|
+
...config.signInOptions,
|
|
32
|
+
redirectUri: `${config.baseUrl}/${prefix}/sign-in-callback`,
|
|
33
|
+
});
|
|
31
34
|
break;
|
|
32
35
|
}
|
|
33
36
|
case 'sign-up': {
|
|
34
|
-
await nodeClient.signIn(
|
|
37
|
+
await nodeClient.signIn({
|
|
38
|
+
...config.signInOptions,
|
|
39
|
+
redirectUri: `${config.baseUrl}/${prefix}/sign-in-callback`,
|
|
40
|
+
firstScreen: 'register',
|
|
41
|
+
});
|
|
35
42
|
break;
|
|
36
43
|
}
|
|
37
44
|
case 'sign-in-callback': {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetContextParameters, LogtoConfig } from '@logto/node';
|
|
1
|
+
import type { GetContextParameters, LogtoConfig, SignInOptions } from '@logto/node';
|
|
2
2
|
declare module 'http' {
|
|
3
3
|
interface IncomingMessage {
|
|
4
4
|
session: Record<string, string | undefined>;
|
|
@@ -7,4 +7,5 @@ declare module 'http' {
|
|
|
7
7
|
export type LogtoExpressConfig = LogtoConfig & {
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
authRoutesPrefix?: string;
|
|
10
|
+
signInOptions?: Omit<SignInOptions, 'redirectUri' | 'postRedirectUri'>;
|
|
10
11
|
} & GetContextParameters;
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./lib/index.cjs",
|
|
6
5
|
"module": "./lib/index.js",
|
|
7
6
|
"types": "./lib/index.d.ts",
|
|
8
7
|
"exports": {
|
|
9
8
|
"types": "./lib/index.d.ts",
|
|
10
|
-
"require": "./lib/index.cjs",
|
|
11
9
|
"import": "./lib/index.js",
|
|
12
10
|
"default": "./lib/index.js"
|
|
13
11
|
},
|
|
@@ -21,7 +19,7 @@
|
|
|
21
19
|
"directory": "packages/express"
|
|
22
20
|
},
|
|
23
21
|
"dependencies": {
|
|
24
|
-
"@logto/node": "^
|
|
22
|
+
"@logto/node": "^3.1.0"
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
|
27
25
|
"@silverhand/eslint-config": "^6.0.1",
|
|
@@ -29,13 +27,13 @@
|
|
|
29
27
|
"@silverhand/ts-config-react": "^6.0.0",
|
|
30
28
|
"@swc/core": "^1.6.5",
|
|
31
29
|
"@types/cookie-parser": "^1.4.3",
|
|
32
|
-
"@types/express": "^
|
|
30
|
+
"@types/express": "^5.0.0",
|
|
33
31
|
"@types/express-session": "^1.17.5",
|
|
34
32
|
"@types/supertest": "^6.0.0",
|
|
35
33
|
"@vitest/coverage-v8": "^1.6.0",
|
|
36
34
|
"cookie-parser": "^1.4.6",
|
|
37
35
|
"eslint": "^8.57.0",
|
|
38
|
-
"express": "^4.
|
|
36
|
+
"express": "^4.20.0",
|
|
39
37
|
"express-session": "^1.17.3",
|
|
40
38
|
"lint-staged": "^15.0.0",
|
|
41
39
|
"prettier": "^3.0.0",
|
|
@@ -68,6 +66,6 @@
|
|
|
68
66
|
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
69
67
|
"lint": "eslint --ext .ts src",
|
|
70
68
|
"test": "vitest",
|
|
71
|
-
"test:coverage": "
|
|
69
|
+
"test:coverage": "vitest --silent --coverage"
|
|
72
70
|
}
|
|
73
71
|
}
|
package/lib/errors.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const logtoExpressErrorCodes = Object.freeze({
|
|
4
|
-
session_not_configured: 'You should configure express-session before using Logto express SDK.',
|
|
5
|
-
});
|
|
6
|
-
class LogtoExpressError extends Error {
|
|
7
|
-
constructor(code, data) {
|
|
8
|
-
super(logtoExpressErrorCodes[code]);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.data = data;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
exports.LogtoExpressError = LogtoExpressError;
|
package/lib/index.cjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var NodeClient = require('@logto/node');
|
|
4
|
-
var express = require('express');
|
|
5
|
-
var errors = require('./errors.cjs');
|
|
6
|
-
var storage = require('./storage.cjs');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var NodeClient__default = /*#__PURE__*/_interopDefault(NodeClient);
|
|
11
|
-
|
|
12
|
-
const createNodeClient = (request, response, config) => {
|
|
13
|
-
// We assume that `session` is configured in the express app, but need to check it there.
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
|
-
if (!request.session) {
|
|
16
|
-
throw new errors.LogtoExpressError('session_not_configured');
|
|
17
|
-
}
|
|
18
|
-
const storage$1 = new storage.default(request);
|
|
19
|
-
return new NodeClient__default.default(config, {
|
|
20
|
-
storage: storage$1,
|
|
21
|
-
navigate: (url) => {
|
|
22
|
-
response.redirect(url);
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const handleAuthRoutes = (config) => {
|
|
27
|
-
// eslint-disable-next-line new-cap
|
|
28
|
-
const router = express.Router();
|
|
29
|
-
const prefix = config.authRoutesPrefix ?? 'logto';
|
|
30
|
-
router.use(`/${prefix}/:action`, async (request, response) => {
|
|
31
|
-
const { action } = request.params;
|
|
32
|
-
const nodeClient = createNodeClient(request, response, config);
|
|
33
|
-
switch (action) {
|
|
34
|
-
case 'sign-in': {
|
|
35
|
-
await nodeClient.signIn(`${config.baseUrl}/${prefix}/sign-in-callback`);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'sign-up': {
|
|
39
|
-
await nodeClient.signIn(`${config.baseUrl}/${prefix}/sign-in-callback`, 'signUp');
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case 'sign-in-callback': {
|
|
43
|
-
if (request.url) {
|
|
44
|
-
await nodeClient.handleSignInCallback(`${config.baseUrl}${request.originalUrl}`);
|
|
45
|
-
response.redirect(config.baseUrl);
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case 'sign-out': {
|
|
50
|
-
await nodeClient.signOut(config.baseUrl);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
default: {
|
|
54
|
-
response.status(404).end();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return router;
|
|
59
|
-
};
|
|
60
|
-
const withLogto = (config) => async (request, response, next) => {
|
|
61
|
-
const client = createNodeClient(request, response, config);
|
|
62
|
-
const user = await client.getContext({
|
|
63
|
-
getAccessToken: config.getAccessToken,
|
|
64
|
-
resource: config.resource,
|
|
65
|
-
fetchUserInfo: config.fetchUserInfo,
|
|
66
|
-
getOrganizationToken: config.getOrganizationToken,
|
|
67
|
-
});
|
|
68
|
-
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
|
|
69
|
-
Object.defineProperty(request, 'user', { enumerable: true, get: () => user });
|
|
70
|
-
next();
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
Object.defineProperty(exports, "LogtoClientError", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function () { return NodeClient.LogtoClientError; }
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(exports, "LogtoError", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
get: function () { return NodeClient.LogtoError; }
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(exports, "LogtoRequestError", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
get: function () { return NodeClient.LogtoRequestError; }
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(exports, "OidcError", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
get: function () { return NodeClient.OidcError; }
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(exports, "PersistKey", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
get: function () { return NodeClient.PersistKey; }
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(exports, "Prompt", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
get: function () { return NodeClient.Prompt; }
|
|
96
|
-
});
|
|
97
|
-
Object.defineProperty(exports, "ReservedResource", {
|
|
98
|
-
enumerable: true,
|
|
99
|
-
get: function () { return NodeClient.ReservedResource; }
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(exports, "ReservedScope", {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
get: function () { return NodeClient.ReservedScope; }
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(exports, "UserScope", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
get: function () { return NodeClient.UserScope; }
|
|
108
|
-
});
|
|
109
|
-
Object.defineProperty(exports, "buildOrganizationUrn", {
|
|
110
|
-
enumerable: true,
|
|
111
|
-
get: function () { return NodeClient.buildOrganizationUrn; }
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(exports, "getOrganizationIdFromUrn", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
get: function () { return NodeClient.getOrganizationIdFromUrn; }
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(exports, "organizationUrnPrefix", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
get: function () { return NodeClient.organizationUrnPrefix; }
|
|
120
|
-
});
|
|
121
|
-
exports.handleAuthRoutes = handleAuthRoutes;
|
|
122
|
-
exports.withLogto = withLogto;
|
package/lib/storage.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
class ExpressStorage {
|
|
6
|
-
constructor(request) {
|
|
7
|
-
this.request = request;
|
|
8
|
-
}
|
|
9
|
-
async setItem(key, value) {
|
|
10
|
-
this.request.session[key] = value;
|
|
11
|
-
}
|
|
12
|
-
async getItem(key) {
|
|
13
|
-
const value = this.request.session[key];
|
|
14
|
-
if (value === undefined) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return String(value);
|
|
18
|
-
}
|
|
19
|
-
async removeItem(key) {
|
|
20
|
-
this.request.session[key] = undefined;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
exports.default = ExpressStorage;
|