@cocreate/authenticate 1.4.2 → 1.4.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/CHANGELOG.md +17 -0
- package/CoCreate.config.js +1 -2
- package/docs/index.html +2 -2
- package/package.json +2 -2
- package/src/index.js +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [1.4.4](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.4.3...v1.4.4) (2023-11-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump dependencies for latest features ([7ace0aa](https://github.com/CoCreate-app/CoCreate-authenticate/commit/7ace0aad830f29823ac86bf7dad2a5aca834dba0))
|
|
7
|
+
|
|
8
|
+
## [1.4.3](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.4.2...v1.4.3) (2023-11-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* date update to ISO format ([eaf2a77](https://github.com/CoCreate-app/CoCreate-authenticate/commit/eaf2a77ff6503021354ae2917279c011ea0fd4f8))
|
|
14
|
+
* meta name typo ([a7299c0](https://github.com/CoCreate-app/CoCreate-authenticate/commit/a7299c0406bbf96e46af9c6e575fe699e4d94773))
|
|
15
|
+
* update crud methods ([e9d0ff0](https://github.com/CoCreate-app/CoCreate-authenticate/commit/e9d0ff09003c2f6e7cde50ec307c3f786bdca0a0))
|
|
16
|
+
* update host ([71a7281](https://github.com/CoCreate-app/CoCreate-authenticate/commit/71a7281a96aa10c79c0e9fcd5a50c852a6d89ef3))
|
|
17
|
+
|
|
1
18
|
## [1.4.2](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.4.1...v1.4.2) (2023-11-03)
|
|
2
19
|
|
|
3
20
|
|
package/CoCreate.config.js
CHANGED
package/docs/index.html
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
sizes="32x32"
|
|
12
12
|
href="https://cocreate.app/images/favicon.ico" />
|
|
13
13
|
<meta
|
|
14
|
-
|
|
14
|
+
name="description"
|
|
15
15
|
content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
|
|
16
16
|
<meta
|
|
17
|
-
|
|
17
|
+
name="keywords"
|
|
18
18
|
content="helper classes, utility classes, css framework, css library, inline style classes" />
|
|
19
19
|
<meta name="robots" content="index,follow" />
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/authenticate",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A simple authenticate component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authenticate",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"main": "./src/index.js",
|
|
41
41
|
"homepage": "https://cocreate.app/docs/authenticate",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cocreate/utils": "^1.
|
|
43
|
+
"@cocreate/utils": "^1.27.1",
|
|
44
44
|
"jsonwebtoken": "^9.0.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/index.js
CHANGED
|
@@ -14,12 +14,12 @@ const users = new Map();
|
|
|
14
14
|
// TODO: user can have multiple sessions
|
|
15
15
|
const activeSessions = new Map();
|
|
16
16
|
|
|
17
|
-
// crud.listen('create
|
|
17
|
+
// crud.listen('object.create', function (data) {
|
|
18
18
|
// if (data.object && data.object[0] && data.object[0].type === 'keyPair')
|
|
19
19
|
// keyPairs.set(data.object[0]._id, data.object[0]);
|
|
20
20
|
// });
|
|
21
21
|
|
|
22
|
-
// crud.listen('delete
|
|
22
|
+
// crud.listen('object.delete', function (data) {
|
|
23
23
|
// if (data.object && data.object[0] && data.object[0].type === 'keyPair')
|
|
24
24
|
// keyPairs.delete(data.object[0]._id);
|
|
25
25
|
// });
|
|
@@ -30,12 +30,13 @@ function createKeyPair() {
|
|
|
30
30
|
modulusLength: 2048,
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
let created = new Date(new Date().toISOString()).getTime()
|
|
33
34
|
const keyPair = {
|
|
34
35
|
_id: ObjectId().toString(),
|
|
35
36
|
privateKey,
|
|
36
37
|
publicKey,
|
|
37
|
-
created
|
|
38
|
-
expires:
|
|
38
|
+
created,
|
|
39
|
+
expires: created + tokenExpiration * 60 * 1000, // Convert minutes to milliseconds
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
keyPairs.set(keyPair._id, keyPair);
|
|
@@ -92,7 +93,7 @@ function deleteKeyPair(keyPair) {
|
|
|
92
93
|
// Function to sign a new token using the newest keyPair
|
|
93
94
|
function encodeToken(payload) {
|
|
94
95
|
let keyPair = null
|
|
95
|
-
const currentTime = new Date().getTime();
|
|
96
|
+
const currentTime = new Date(new Date().toISOString()).getTime();
|
|
96
97
|
for (let [key, value] of keyPairs) {
|
|
97
98
|
if (currentTime > value.expires) {
|
|
98
99
|
deleteKeyPair(value);
|
|
@@ -108,7 +109,7 @@ function encodeToken(payload) {
|
|
|
108
109
|
// TODO: payload could have previous user ip and device information which we could use to comapre to current ip and device information
|
|
109
110
|
|
|
110
111
|
const token = jwt.sign(payload, keyPair.privateKey, { algorithm: 'RS256', expiresIn: tokenExpiration * 60 });
|
|
111
|
-
users.set(token, { _id: payload.user_id, expires:
|
|
112
|
+
users.set(token, { _id: payload.user_id, expires: currentTime + tokenExpiration * 60 * 1000 })
|
|
112
113
|
return token;
|
|
113
114
|
}
|
|
114
115
|
|