@twin.org/api-auth-entity-storage-service 0.0.1-next.9 → 0.0.2-next.1

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 (31) hide show
  1. package/dist/cjs/index.cjs +221 -19
  2. package/dist/esm/index.mjs +223 -23
  3. package/dist/types/index.d.ts +5 -0
  4. package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +15 -0
  5. package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +10 -0
  6. package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +15 -0
  7. package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +25 -0
  8. package/dist/types/processors/authHeaderProcessor.d.ts +10 -11
  9. package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +9 -1
  10. package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +42 -0
  11. package/dist/types/services/entityStorageAuthenticationService.d.ts +14 -9
  12. package/dist/types/utils/tokenHelper.d.ts +1 -1
  13. package/docs/changelog.md +115 -1
  14. package/docs/reference/classes/AuthHeaderProcessor.md +50 -28
  15. package/docs/reference/classes/AuthenticationUser.md +3 -3
  16. package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +149 -0
  17. package/docs/reference/classes/EntityStorageAuthenticationService.md +71 -39
  18. package/docs/reference/classes/PasswordHelper.md +9 -5
  19. package/docs/reference/classes/TokenHelper.md +36 -34
  20. package/docs/reference/functions/authenticationLogin.md +9 -3
  21. package/docs/reference/functions/authenticationLogout.md +9 -3
  22. package/docs/reference/functions/authenticationRefreshToken.md +9 -3
  23. package/docs/reference/functions/authenticationUpdatePassword.md +31 -0
  24. package/docs/reference/functions/generateRestRoutesAuthentication.md +8 -4
  25. package/docs/reference/index.md +6 -0
  26. package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +25 -0
  27. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +17 -0
  28. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +25 -0
  29. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +53 -0
  30. package/locales/en.json +10 -1
  31. package/package.json +6 -6
@@ -0,0 +1,149 @@
1
+ # Class: EntityStorageAuthenticationAdminService
2
+
3
+ Implementation of the authentication component using entity storage.
4
+
5
+ ## Implements
6
+
7
+ - `IAuthenticationAdminComponent`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new EntityStorageAuthenticationAdminService**(`options?`): `EntityStorageAuthenticationAdminService`
14
+
15
+ Create a new instance of EntityStorageAuthentication.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`IEntityStorageAuthenticationAdminServiceConstructorOptions`](../interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md)
22
+
23
+ The dependencies for the identity connector.
24
+
25
+ #### Returns
26
+
27
+ `EntityStorageAuthenticationAdminService`
28
+
29
+ ## Properties
30
+
31
+ ### NAMESPACE
32
+
33
+ > `readonly` `static` **NAMESPACE**: `string` = `"authentication-admin-entity-storage"`
34
+
35
+ The namespace supported by the authentication service.
36
+
37
+ ***
38
+
39
+ ### CLASS\_NAME
40
+
41
+ > `readonly` **CLASS\_NAME**: `string`
42
+
43
+ Runtime name for the class.
44
+
45
+ #### Implementation of
46
+
47
+ `IAuthenticationAdminComponent.CLASS_NAME`
48
+
49
+ ## Methods
50
+
51
+ ### create()
52
+
53
+ > **create**(`email`, `password`, `identity`): `Promise`\<`void`\>
54
+
55
+ Create a login for the user.
56
+
57
+ #### Parameters
58
+
59
+ ##### email
60
+
61
+ `string`
62
+
63
+ The email address for the user.
64
+
65
+ ##### password
66
+
67
+ `string`
68
+
69
+ The password for the user.
70
+
71
+ ##### identity
72
+
73
+ `string`
74
+
75
+ The DID to associate with the account.
76
+
77
+ #### Returns
78
+
79
+ `Promise`\<`void`\>
80
+
81
+ Nothing.
82
+
83
+ #### Implementation of
84
+
85
+ `IAuthenticationAdminComponent.create`
86
+
87
+ ***
88
+
89
+ ### remove()
90
+
91
+ > **remove**(`email`): `Promise`\<`void`\>
92
+
93
+ Remove the current user.
94
+
95
+ #### Parameters
96
+
97
+ ##### email
98
+
99
+ `string`
100
+
101
+ The email address of the user to remove.
102
+
103
+ #### Returns
104
+
105
+ `Promise`\<`void`\>
106
+
107
+ Nothing.
108
+
109
+ #### Implementation of
110
+
111
+ `IAuthenticationAdminComponent.remove`
112
+
113
+ ***
114
+
115
+ ### updatePassword()
116
+
117
+ > **updatePassword**(`email`, `newPassword`, `currentPassword?`): `Promise`\<`void`\>
118
+
119
+ Update the user's password.
120
+
121
+ #### Parameters
122
+
123
+ ##### email
124
+
125
+ `string`
126
+
127
+ The email address of the user to update.
128
+
129
+ ##### newPassword
130
+
131
+ `string`
132
+
133
+ The new password for the user.
134
+
135
+ ##### currentPassword?
136
+
137
+ `string`
138
+
139
+ The current password, optional, if supplied will check against existing.
140
+
141
+ #### Returns
142
+
143
+ `Promise`\<`void`\>
144
+
145
+ Nothing.
146
+
147
+ #### Implementation of
148
+
149
+ `IAuthenticationAdminComponent.updatePassword`
@@ -8,35 +8,33 @@ Implementation of the authentication component using entity storage.
8
8
 
9
9
  ## Constructors
10
10
 
11
- ### new EntityStorageAuthenticationService()
11
+ ### Constructor
12
12
 
13
- > **new EntityStorageAuthenticationService**(`options`?): [`EntityStorageAuthenticationService`](EntityStorageAuthenticationService.md)
13
+ > **new EntityStorageAuthenticationService**(`options?`): `EntityStorageAuthenticationService`
14
14
 
15
15
  Create a new instance of EntityStorageAuthentication.
16
16
 
17
17
  #### Parameters
18
18
 
19
- **options?**
19
+ ##### options?
20
20
 
21
- The dependencies for the identity connector.
22
-
23
- • **options.userEntityStorageType?**: `string`
21
+ [`IEntityStorageAuthenticationServiceConstructorOptions`](../interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md)
24
22
 
25
- The entity storage for the users, defaults to "authentication-user".
23
+ The dependencies for the identity connector.
26
24
 
27
- **options.vaultConnectorType?**: `string`
25
+ #### Returns
28
26
 
29
- The vault for the private keys, defaults to "vault".
27
+ `EntityStorageAuthenticationService`
30
28
 
31
- **options.config?**: [`IEntityStorageAuthenticationServiceConfig`](../interfaces/IEntityStorageAuthenticationServiceConfig.md)
29
+ ## Properties
32
30
 
33
- The configuration for the authentication.
31
+ ### NAMESPACE
34
32
 
35
- #### Returns
33
+ > `readonly` `static` **NAMESPACE**: `string` = `"authentication-entity-storage"`
36
34
 
37
- [`EntityStorageAuthenticationService`](EntityStorageAuthenticationService.md)
35
+ The namespace supported by the authentication service.
38
36
 
39
- ## Properties
37
+ ***
40
38
 
41
39
  ### CLASS\_NAME
42
40
 
@@ -52,17 +50,21 @@ Runtime name for the class.
52
50
 
53
51
  ### start()
54
52
 
55
- > **start**(`nodeIdentity`, `nodeLoggingConnectorType`?): `Promise`\<`void`\>
53
+ > **start**(`nodeIdentity`, `nodeLoggingConnectorType?`): `Promise`\<`void`\>
56
54
 
57
55
  The service needs to be started when the application is initialized.
58
56
 
59
57
  #### Parameters
60
58
 
61
- **nodeIdentity**: `string`
59
+ ##### nodeIdentity
60
+
61
+ `string`
62
62
 
63
63
  The identity of the node.
64
64
 
65
- **nodeLoggingConnectorType?**: `string`
65
+ ##### nodeLoggingConnectorType?
66
+
67
+ `string`
66
68
 
67
69
  The node logging connector type, defaults to "node-logging".
68
70
 
@@ -80,34 +82,30 @@ Nothing.
80
82
 
81
83
  ### login()
82
84
 
83
- > **login**(`email`, `password`): `Promise`\<`object`\>
85
+ > **login**(`email`, `password`): `Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
84
86
 
85
87
  Perform a login for the user.
86
88
 
87
89
  #### Parameters
88
90
 
89
- **email**: `string`
91
+ ##### email
92
+
93
+ `string`
90
94
 
91
95
  The email address for the user.
92
96
 
93
- **password**: `string`
97
+ ##### password
98
+
99
+ `string`
94
100
 
95
101
  The password for the user.
96
102
 
97
103
  #### Returns
98
104
 
99
- `Promise`\<`object`\>
105
+ `Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
100
106
 
101
107
  The authentication token for the user, if it uses a mechanism with public access.
102
108
 
103
- ##### token?
104
-
105
- > `optional` **token**: `string`
106
-
107
- ##### expiry
108
-
109
- > **expiry**: `number`
110
-
111
109
  #### Implementation of
112
110
 
113
111
  `IAuthenticationComponent.login`
@@ -116,13 +114,15 @@ The authentication token for the user, if it uses a mechanism with public access
116
114
 
117
115
  ### logout()
118
116
 
119
- > **logout**(`token`?): `Promise`\<`void`\>
117
+ > **logout**(`token?`): `Promise`\<`void`\>
120
118
 
121
119
  Logout the current user.
122
120
 
123
121
  #### Parameters
124
122
 
125
- **token?**: `string`
123
+ ##### token?
124
+
125
+ `string`
126
126
 
127
127
  The token to logout, if it uses a mechanism with public access.
128
128
 
@@ -140,30 +140,62 @@ Nothing.
140
140
 
141
141
  ### refresh()
142
142
 
143
- > **refresh**(`token`?): `Promise`\<`object`\>
143
+ > **refresh**(`token?`): `Promise`\<\{ `token`: `string`; `expiry`: `number`; \}\>
144
144
 
145
145
  Refresh the token.
146
146
 
147
147
  #### Parameters
148
148
 
149
- **token?**: `string`
149
+ ##### token?
150
+
151
+ `string`
150
152
 
151
153
  The token to refresh, if it uses a mechanism with public access.
152
154
 
153
155
  #### Returns
154
156
 
155
- `Promise`\<`object`\>
157
+ `Promise`\<\{ `token`: `string`; `expiry`: `number`; \}\>
156
158
 
157
159
  The refreshed token, if it uses a mechanism with public access.
158
160
 
159
- ##### token
161
+ #### Implementation of
162
+
163
+ `IAuthenticationComponent.refresh`
164
+
165
+ ***
166
+
167
+ ### updatePassword()
168
+
169
+ > **updatePassword**(`email`, `currentPassword`, `newPassword`): `Promise`\<`void`\>
170
+
171
+ Update the user's password.
172
+
173
+ #### Parameters
174
+
175
+ ##### email
176
+
177
+ `string`
160
178
 
161
- > **token**: `string`
179
+ The email address of the user to update.
162
180
 
163
- ##### expiry
181
+ ##### currentPassword
164
182
 
165
- > **expiry**: `number`
183
+ `string`
184
+
185
+ The current password for the user.
186
+
187
+ ##### newPassword
188
+
189
+ `string`
190
+
191
+ The new password for the user.
192
+
193
+ #### Returns
194
+
195
+ `Promise`\<`void`\>
196
+
197
+ Nothing.
166
198
 
167
199
  #### Implementation of
168
200
 
169
- `IAuthenticationComponent.refresh`
201
+ `IAuthenticationComponent.updatePassword`
@@ -4,13 +4,13 @@ Helper class for password operations.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new PasswordHelper()
7
+ ### Constructor
8
8
 
9
- > **new PasswordHelper**(): [`PasswordHelper`](PasswordHelper.md)
9
+ > **new PasswordHelper**(): `PasswordHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`PasswordHelper`](PasswordHelper.md)
13
+ `PasswordHelper`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,11 +22,15 @@ Hash the password for the user.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **passwordBytes**: `Uint8Array`
25
+ ##### passwordBytes
26
+
27
+ `Uint8Array`
26
28
 
27
29
  The password bytes.
28
30
 
29
- **saltBytes**: `Uint8Array`
31
+ ##### saltBytes
32
+
33
+ `Uint8Array`
30
34
 
31
35
  The salt bytes.
32
36
 
@@ -4,90 +4,88 @@ Helper class for token operations.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new TokenHelper()
7
+ ### Constructor
8
8
 
9
- > **new TokenHelper**(): [`TokenHelper`](TokenHelper.md)
9
+ > **new TokenHelper**(): `TokenHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`TokenHelper`](TokenHelper.md)
13
+ `TokenHelper`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### createToken()
18
18
 
19
- > `static` **createToken**(`vaultConnector`, `signingKeyName`, `subject`, `ttlMinutes`): `Promise`\<`object`\>
19
+ > `static` **createToken**(`vaultConnector`, `signingKeyName`, `subject`, `ttlMinutes`): `Promise`\<\{ `token`: `string`; `expiry`: `number`; \}\>
20
20
 
21
21
  Create a new token.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **vaultConnector**: `IVaultConnector`
25
+ ##### vaultConnector
26
+
27
+ `IVaultConnector`
26
28
 
27
29
  The vault connector.
28
30
 
29
- **signingKeyName**: `string`
31
+ ##### signingKeyName
32
+
33
+ `string`
30
34
 
31
35
  The signing key name.
32
36
 
33
- **subject**: `string`
37
+ ##### subject
38
+
39
+ `string`
34
40
 
35
41
  The subject for the token.
36
42
 
37
- **ttlMinutes**: `number`
43
+ ##### ttlMinutes
44
+
45
+ `number`
38
46
 
39
47
  The time to live for the token in minutes.
40
48
 
41
49
  #### Returns
42
50
 
43
- `Promise`\<`object`\>
51
+ `Promise`\<\{ `token`: `string`; `expiry`: `number`; \}\>
44
52
 
45
53
  The new token and its expiry date.
46
54
 
47
- ##### token
48
-
49
- > **token**: `string`
50
-
51
- ##### expiry
52
-
53
- > **expiry**: `number`
54
-
55
55
  ***
56
56
 
57
57
  ### verify()
58
58
 
59
- > `static` **verify**(`vaultConnector`, `signingKeyName`, `token`): `Promise`\<`object`\>
59
+ > `static` **verify**(`vaultConnector`, `signingKeyName`, `token`): `Promise`\<\{ `header`: `IJwtHeader`; `payload`: `IJwtPayload`; \}\>
60
60
 
61
61
  Verify the token.
62
62
 
63
63
  #### Parameters
64
64
 
65
- **vaultConnector**: `IVaultConnector`
65
+ ##### vaultConnector
66
+
67
+ `IVaultConnector`
66
68
 
67
69
  The vault connector.
68
70
 
69
- **signingKeyName**: `string`
71
+ ##### signingKeyName
72
+
73
+ `string`
70
74
 
71
75
  The signing key name.
72
76
 
73
- **token**: `undefined` \| `string`
77
+ ##### token
74
78
 
75
79
  The token to verify.
76
80
 
81
+ `undefined` | `string`
82
+
77
83
  #### Returns
78
84
 
79
- `Promise`\<`object`\>
85
+ `Promise`\<\{ `header`: `IJwtHeader`; `payload`: `IJwtPayload`; \}\>
80
86
 
81
87
  The verified details.
82
88
 
83
- ##### header
84
-
85
- > **header**: `IJwtHeader`
86
-
87
- ##### payload
88
-
89
- > **payload**: `IJwtPayload`
90
-
91
89
  #### Throws
92
90
 
93
91
  UnauthorizedError if the token is missing, invalid or expired.
@@ -96,22 +94,26 @@ UnauthorizedError if the token is missing, invalid or expired.
96
94
 
97
95
  ### extractTokenFromHeaders()
98
96
 
99
- > `static` **extractTokenFromHeaders**(`headers`?, `cookieName`?): `undefined` \| `object`
97
+ > `static` **extractTokenFromHeaders**(`headers?`, `cookieName?`): `undefined` \| \{ `token`: `string`; `location`: `"authorization"` \| `"cookie"`; \}
100
98
 
101
99
  Extract the auth token from the headers, either from the authorization header or the cookie header.
102
100
 
103
101
  #### Parameters
104
102
 
105
- **headers?**: `IHttpHeaders`
103
+ ##### headers?
104
+
105
+ `IHttpHeaders`
106
106
 
107
107
  The headers to extract the token from.
108
108
 
109
- **cookieName?**: `string`
109
+ ##### cookieName?
110
+
111
+ `string`
110
112
 
111
113
  The name of the cookie to extract the token from.
112
114
 
113
115
  #### Returns
114
116
 
115
- `undefined` \| `object`
117
+ `undefined` \| \{ `token`: `string`; `location`: `"authorization"` \| `"cookie"`; \}
116
118
 
117
119
  The token if found.
@@ -6,15 +6,21 @@ Login to the server.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **httpRequestContext**: `IHttpRequestContext`
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
10
12
 
11
13
  The request context for the API.
12
14
 
13
- **componentName**: `string`
15
+ ### componentName
16
+
17
+ `string`
14
18
 
15
19
  The name of the component to use in the routes.
16
20
 
17
- **request**: `ILoginRequest`
21
+ ### request
22
+
23
+ `ILoginRequest`
18
24
 
19
25
  The request.
20
26
 
@@ -6,15 +6,21 @@ Logout from the server.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **httpRequestContext**: `IHttpRequestContext`
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
10
12
 
11
13
  The request context for the API.
12
14
 
13
- **componentName**: `string`
15
+ ### componentName
16
+
17
+ `string`
14
18
 
15
19
  The name of the component to use in the routes.
16
20
 
17
- **request**: `ILogoutRequest`
21
+ ### request
22
+
23
+ `ILogoutRequest`
18
24
 
19
25
  The request.
20
26
 
@@ -6,15 +6,21 @@ Refresh the login token.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **httpRequestContext**: `IHttpRequestContext`
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
10
12
 
11
13
  The request context for the API.
12
14
 
13
- **componentName**: `string`
15
+ ### componentName
16
+
17
+ `string`
14
18
 
15
19
  The name of the component to use in the routes.
16
20
 
17
- **request**: `IRefreshTokenRequest`
21
+ ### request
22
+
23
+ `IRefreshTokenRequest`
18
24
 
19
25
  The request.
20
26
 
@@ -0,0 +1,31 @@
1
+ # Function: authenticationUpdatePassword()
2
+
3
+ > **authenticationUpdatePassword**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
4
+
5
+ Update the user's password.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `IUpdatePasswordRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`INoContentResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -1,21 +1,25 @@
1
1
  # Function: generateRestRoutesAuthentication()
2
2
 
3
- > **generateRestRoutesAuthentication**(`baseRouteName`, `componentName`): `IRestRoute`[]
3
+ > **generateRestRoutesAuthentication**(`baseRouteName`, `componentName`): `IRestRoute`\<`any`, `any`\>[]
4
4
 
5
5
  The REST routes for authentication.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **baseRouteName**: `string`
9
+ ### baseRouteName
10
+
11
+ `string`
10
12
 
11
13
  Prefix to prepend to the paths.
12
14
 
13
- **componentName**: `string`
15
+ ### componentName
16
+
17
+ `string`
14
18
 
15
19
  The name of the component to use in the routes stored in the ComponentFactory.
16
20
 
17
21
  ## Returns
18
22
 
19
- `IRestRoute`[]
23
+ `IRestRoute`\<`any`, `any`\>[]
20
24
 
21
25
  The generated routes.
@@ -4,6 +4,7 @@
4
4
 
5
5
  - [AuthenticationUser](classes/AuthenticationUser.md)
6
6
  - [AuthHeaderProcessor](classes/AuthHeaderProcessor.md)
7
+ - [EntityStorageAuthenticationAdminService](classes/EntityStorageAuthenticationAdminService.md)
7
8
  - [EntityStorageAuthenticationService](classes/EntityStorageAuthenticationService.md)
8
9
  - [PasswordHelper](classes/PasswordHelper.md)
9
10
  - [TokenHelper](classes/TokenHelper.md)
@@ -11,7 +12,11 @@
11
12
  ## Interfaces
12
13
 
13
14
  - [IAuthHeaderProcessorConfig](interfaces/IAuthHeaderProcessorConfig.md)
15
+ - [IAuthHeaderProcessorConstructorOptions](interfaces/IAuthHeaderProcessorConstructorOptions.md)
16
+ - [IEntityStorageAuthenticationAdminServiceConfig](interfaces/IEntityStorageAuthenticationAdminServiceConfig.md)
17
+ - [IEntityStorageAuthenticationAdminServiceConstructorOptions](interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md)
14
18
  - [IEntityStorageAuthenticationServiceConfig](interfaces/IEntityStorageAuthenticationServiceConfig.md)
19
+ - [IEntityStorageAuthenticationServiceConstructorOptions](interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md)
15
20
 
16
21
  ## Variables
17
22
 
@@ -24,4 +29,5 @@
24
29
  - [authenticationLogin](functions/authenticationLogin.md)
25
30
  - [authenticationLogout](functions/authenticationLogout.md)
26
31
  - [authenticationRefreshToken](functions/authenticationRefreshToken.md)
32
+ - [authenticationUpdatePassword](functions/authenticationUpdatePassword.md)
27
33
  - [initSchema](functions/initSchema.md)