@1auth/authn 0.0.0-alpha.0 → 0.0.0-alpha.10

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.
Files changed (2) hide show
  1. package/index.js +11 -9
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -11,6 +11,7 @@ export const options = {
11
11
  export default (params) => {
12
12
  Object.assign(options, params)
13
13
  }
14
+ export const getOptions = () => options
14
15
 
15
16
  export const create = async (
16
17
  credentialType,
@@ -31,7 +32,7 @@ export const create = async (
31
32
  encryptedKey,
32
33
  sub
33
34
  )
34
- return parentOptions.store.insert(options.table, {
35
+ await options.store.insert(options.table, {
35
36
  expire,
36
37
  ...rest,
37
38
  id,
@@ -43,6 +44,7 @@ export const create = async (
43
44
  create: now,
44
45
  update: now
45
46
  })
47
+ return id
46
48
  }
47
49
 
48
50
  export const update = async (
@@ -56,7 +58,7 @@ export const update = async (
56
58
  encryptionKey,
57
59
  sub
58
60
  )
59
- return parentOptions.store.update(
61
+ return options.store.update(
60
62
  options.table,
61
63
  { id, sub },
62
64
  {
@@ -81,7 +83,7 @@ export const authenticate = async (username, secret, parentOptions) => {
81
83
 
82
84
  const sub = await subject(username)
83
85
 
84
- const credentials = await parentOptions.store.selectList(options.table, {
86
+ const credentials = await options.store.selectList(options.table, {
85
87
  sub,
86
88
  type
87
89
  }) // TODO and verify is not null
@@ -98,7 +100,7 @@ export const authenticate = async (username, secret, parentOptions) => {
98
100
  }
99
101
 
100
102
  if (valid && parentOptions.secret.otp) {
101
- await parentOptions.store.remove(options.table, { id, sub })
103
+ await options.store.remove(options.table, { id, sub })
102
104
  }
103
105
  await timeout
104
106
  if (!valid) throw new Error('401 Unauthorized')
@@ -107,7 +109,7 @@ export const authenticate = async (username, secret, parentOptions) => {
107
109
 
108
110
  export const verifySecret = async (sub, id, parentOptions) => {
109
111
  // const type = parentOptions.id + '-' + parentOptions.secret.type
110
- await parentOptions.store.update(
112
+ await options.store.update(
111
113
  options.table,
112
114
  { id, sub },
113
115
  { verify: nowInSeconds() }
@@ -118,7 +120,7 @@ export const verify = async (credentialType, sub, token, parentOptions) => {
118
120
  const timeout = setTimeout(() => {}, options.authenticationDuration)
119
121
  const type = parentOptions.id + '-' + parentOptions[credentialType].type
120
122
  let id
121
- const credentials = await parentOptions.store.selectList(options.table, {
123
+ const credentials = await options.store.selectList(options.table, {
122
124
  sub,
123
125
  type
124
126
  })
@@ -128,7 +130,7 @@ export const verify = async (credentialType, sub, token, parentOptions) => {
128
130
  // return rows
129
131
  // }
130
132
  //
131
- // return parentOptions.store.select(options.table, { id: sub, type })
133
+ // return options.store.select(options.table, { id: sub, type })
132
134
  // })
133
135
 
134
136
  let valid
@@ -146,7 +148,7 @@ export const verify = async (credentialType, sub, token, parentOptions) => {
146
148
  }
147
149
  }
148
150
  if (valid && parentOptions[credentialType].otp) {
149
- await parentOptions.store.remove(options.table, { id, sub })
151
+ await options.store.remove(options.table, { id, sub })
150
152
  }
151
153
  if (!valid) throw new Error('401 Unauthorized')
152
154
  await timeout
@@ -154,7 +156,7 @@ export const verify = async (credentialType, sub, token, parentOptions) => {
154
156
  }
155
157
 
156
158
  export const expire = async (sub, id, parentOptions = options) => {
157
- await parentOptions.store.remove(options.table, { id, sub })
159
+ await options.store.remove(options.table, { id, sub })
158
160
  }
159
161
 
160
162
  // TODO manage onboard state
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@1auth/authn",
3
- "version": "0.0.0-alpha.0",
3
+ "version": "0.0.0-alpha.10",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=18"
7
+ "node": ">=16"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
@@ -48,8 +48,8 @@
48
48
  "url": "https://github.com/willfarrell/1auth/issues"
49
49
  },
50
50
  "homepage": "https://github.com/willfarrell/1auth",
51
- "gitHead": "dcd3cb3dcacdebbe21625f092187e7cf02473f68",
51
+ "gitHead": "40d015ce640f9813d809fddb847f60974c596b46",
52
52
  "dependencies": {
53
- "@1auth/crypto": "0.0.0-alpha.0"
53
+ "@1auth/crypto": "0.0.0-alpha.10"
54
54
  }
55
55
  }