@cocreate/authenticate 1.3.8 → 1.4.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 +15 -0
- package/package.json +2 -2
- package/src/index.js +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.3.9...v1.4.0) (2023-10-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* ObjectId() returns an object containg the parts iof the _id along with a toString() function ([dcff174](https://github.com/CoCreate-app/CoCreate-authenticate/commit/dcff174fb8c70c48dce2c13a613170de0aaa1727))
|
|
7
|
+
|
|
8
|
+
## [1.3.9](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.3.8...v1.3.9) (2023-10-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* added '@cocreate/utils' for ObjectId() ([aabc2f3](https://github.com/CoCreate-app/CoCreate-authenticate/commit/aabc2f3aa89aa39c93a50aca76b96c4a6c3da093))
|
|
14
|
+
* key creation ([71b759d](https://github.com/CoCreate-app/CoCreate-authenticate/commit/71b759d216da7b30a2f5fb94d6783ac0ff52cdc1))
|
|
15
|
+
|
|
1
16
|
## [1.3.8](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.3.7...v1.3.8) (2023-10-14)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/authenticate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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/
|
|
43
|
+
"@cocreate/utils": "^1.25.4",
|
|
44
44
|
"jsonwebtoken": "^9.0.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
1
2
|
const jwt = require('jsonwebtoken');
|
|
3
|
+
const { ObjectId } = require('@cocreate/utils');
|
|
2
4
|
|
|
3
5
|
// Configuration
|
|
4
6
|
const tokenExpiration = 60; // Token expiration in minutes
|
|
@@ -24,12 +26,12 @@ const activeSessions = new Map();
|
|
|
24
26
|
|
|
25
27
|
// Create new RSA key pair
|
|
26
28
|
function createKeyPair() {
|
|
27
|
-
const { privateKey, publicKey } =
|
|
29
|
+
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
|
|
28
30
|
modulusLength: 2048,
|
|
29
31
|
});
|
|
30
32
|
|
|
31
33
|
const keyPair = {
|
|
32
|
-
_id:
|
|
34
|
+
_id: ObjectId().toString(),
|
|
33
35
|
privateKey,
|
|
34
36
|
publicKey,
|
|
35
37
|
created: new Date().getTime(), // Store as timestamp
|
|
@@ -105,8 +107,8 @@ function encodeToken(payload) {
|
|
|
105
107
|
|
|
106
108
|
// TODO: payload could have previous user ip and device information which we could use to comapre to current ip and device information
|
|
107
109
|
|
|
108
|
-
const token = jwt.sign(payload, keyPair.privateKey, { expiresIn: tokenExpiration * 60 });
|
|
109
|
-
users.set(token, { _id: payload.
|
|
110
|
+
const token = jwt.sign(payload, keyPair.privateKey, { algorithm: 'RS256', expiresIn: tokenExpiration * 60 });
|
|
111
|
+
users.set(token, { _id: payload.user_id, expires: new Date().getTime() + tokenExpiration * 60 * 1000 })
|
|
110
112
|
return token;
|
|
111
113
|
}
|
|
112
114
|
|