@1auth/authn 0.0.0-alpha.44 → 0.0.0-alpha.46
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/index.js +19 -12
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setTimeout } from 'node:timers/promises'
|
|
2
2
|
import {
|
|
3
3
|
randomId,
|
|
4
|
-
|
|
4
|
+
symmetricGenerateEncryptionKey,
|
|
5
5
|
symmetricEncryptFields,
|
|
6
6
|
symmetricDecryptFields
|
|
7
7
|
} from '@1auth/crypto'
|
|
@@ -60,7 +60,7 @@ export const count = async (credentialOptions, sub) => {
|
|
|
60
60
|
|
|
61
61
|
export const list = async (credentialOptions, sub, params, fields) => {
|
|
62
62
|
const type = makeType(credentialOptions)
|
|
63
|
-
const
|
|
63
|
+
const items = await options.store.selectList(
|
|
64
64
|
options.table,
|
|
65
65
|
{
|
|
66
66
|
...params,
|
|
@@ -71,20 +71,20 @@ export const list = async (credentialOptions, sub, params, fields) => {
|
|
|
71
71
|
)
|
|
72
72
|
// const now = nowInSeconds();
|
|
73
73
|
const list = []
|
|
74
|
-
for (let i =
|
|
75
|
-
const
|
|
74
|
+
for (let i = items.length; i--;) {
|
|
75
|
+
const item = items[i]
|
|
76
76
|
// TODO need filter for expire
|
|
77
77
|
// if (credential.expire < now) {
|
|
78
78
|
// continue;
|
|
79
79
|
// }
|
|
80
|
-
const { encryptionKey: encryptedKey } =
|
|
81
|
-
delete
|
|
82
|
-
const
|
|
83
|
-
|
|
80
|
+
const { encryptionKey: encryptedKey } = item
|
|
81
|
+
delete item.encryptionKey
|
|
82
|
+
const decryptedItem = symmetricDecryptFields(
|
|
83
|
+
item,
|
|
84
84
|
{ encryptedKey, sub },
|
|
85
85
|
options.encryptedFields
|
|
86
86
|
)
|
|
87
|
-
list.push(
|
|
87
|
+
list.push(decryptedItem)
|
|
88
88
|
}
|
|
89
89
|
return list
|
|
90
90
|
}
|
|
@@ -105,7 +105,7 @@ export const create = async (
|
|
|
105
105
|
value ??= credentialOptions.create()
|
|
106
106
|
const encodedValue = await credentialOptions.encode(value)
|
|
107
107
|
|
|
108
|
-
const { encryptionKey, encryptedKey } =
|
|
108
|
+
const { encryptionKey, encryptedKey } = symmetricGenerateEncryptionKey(sub)
|
|
109
109
|
const encryptedValues = symmetricEncryptFields(
|
|
110
110
|
{ ...values, value: encodedValue },
|
|
111
111
|
{ encryptionKey, sub },
|
|
@@ -176,6 +176,7 @@ export const authenticate = async (credentialOptions, username, secret) => {
|
|
|
176
176
|
},
|
|
177
177
|
['id', 'encryptionKey', 'value', 'otp', 'verify', 'expire', 'sourceId']
|
|
178
178
|
)
|
|
179
|
+
const now = nowInSeconds()
|
|
179
180
|
let valid
|
|
180
181
|
for (const credential of credentials) {
|
|
181
182
|
// non-opt credentials must be verified before use
|
|
@@ -194,7 +195,11 @@ export const authenticate = async (credentialOptions, username, secret) => {
|
|
|
194
195
|
if (valid) {
|
|
195
196
|
const { id, otp } = credential
|
|
196
197
|
if (otp) {
|
|
197
|
-
await options.store.
|
|
198
|
+
await options.store.update(
|
|
199
|
+
options.table,
|
|
200
|
+
{ id, sub },
|
|
201
|
+
{ update: now, expire: now, lastused: now }
|
|
202
|
+
)
|
|
198
203
|
} else if (credentialOptions.clean) {
|
|
199
204
|
await credentialOptions.clean(sub, value, values)
|
|
200
205
|
} else {
|
|
@@ -211,7 +216,9 @@ export const authenticate = async (credentialOptions, username, secret) => {
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
await timeout
|
|
214
|
-
if (!valid)
|
|
219
|
+
if (!valid) {
|
|
220
|
+
throw new Error('401 Unauthorized')
|
|
221
|
+
}
|
|
215
222
|
return sub
|
|
216
223
|
}
|
|
217
224
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1auth/authn",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.46",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"homepage": "https://github.com/willfarrell/1auth",
|
|
51
51
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@1auth/crypto": "0.0.0-alpha.
|
|
53
|
+
"@1auth/crypto": "0.0.0-alpha.46"
|
|
54
54
|
}
|
|
55
55
|
}
|