@furystack/rest-service 4.1.12 → 5.0.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/dist/actions/index.js +6 -6
- package/dist/actions/index.js.map +1 -1
- package/dist/api-manager.js +2 -2
- package/dist/api-manager.js.map +1 -1
- package/dist/endpoint-generators/create-delete-endpoint.spec.js +1 -1
- package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-patch-endpoint.spec.js +1 -1
- package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-post-endpoint.spec.js +1 -1
- package/dist/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/index.js +5 -5
- package/dist/endpoint-generators/index.js.map +1 -1
- package/dist/http-authentication-settings.d.ts +1 -4
- package/dist/http-authentication-settings.d.ts.map +1 -1
- package/dist/http-authentication-settings.js +1 -3
- package/dist/http-authentication-settings.js.map +1 -1
- package/dist/http-user-context.d.ts +5 -8
- package/dist/http-user-context.d.ts.map +1 -1
- package/dist/http-user-context.js +19 -28
- package/dist/http-user-context.js.map +1 -1
- package/dist/http-user-context.spec.d.ts.map +1 -1
- package/dist/http-user-context.spec.js +33 -26
- package/dist/http-user-context.spec.js.map +1 -1
- package/dist/incoming-message-extensions.js +1 -1
- package/dist/incoming-message-extensions.js.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/models/index.js +2 -2
- package/dist/models/index.js.map +1 -1
- package/dist/rest-service.integration.spec.js +1 -1
- package/dist/rest-service.integration.spec.js.map +1 -1
- package/dist/schema-validator/index.js +2 -2
- package/dist/schema-validator/index.js.map +1 -1
- package/dist/schema-validator/schema-validator.js +2 -2
- package/dist/schema-validator/schema-validator.js.map +1 -1
- package/dist/server-manager.js +2 -2
- package/dist/server-manager.js.map +1 -1
- package/dist/server-response-extensions.js +1 -1
- package/dist/server-response-extensions.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/validate.integration.spec.js +1 -1
- package/dist/validate.integration.spec.js.map +1 -1
- package/dist/validate.js.map +1 -1
- package/package.json +12 -12
- package/src/http-authentication-settings.ts +2 -5
- package/src/http-user-context.spec.ts +44 -26
- package/src/http-user-context.ts +15 -25
package/src/http-user-context.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Injectable } from '@furystack/inject'
|
|
|
4
4
|
import { v1 } from 'uuid'
|
|
5
5
|
import { HttpAuthenticationSettings } from './http-authentication-settings'
|
|
6
6
|
import { DefaultSession } from 'models/default-session'
|
|
7
|
+
import { PasswordAuthenticator, UnauthenticatedError } from '@furystack/security'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Injectable UserContext for FuryStack HTTP Api
|
|
@@ -54,21 +55,16 @@ export class HttpUserContext {
|
|
|
54
55
|
* @returns the authenticated User
|
|
55
56
|
*/
|
|
56
57
|
public async authenticateUser(userName: string, password: string) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}))) ||
|
|
66
|
-
[]
|
|
67
|
-
if (match.length === 1) {
|
|
68
|
-
const { password: pw, ...user } = match[0]
|
|
69
|
-
return user
|
|
58
|
+
const result = await this.authenticator.checkPasswordForUser(userName, password)
|
|
59
|
+
|
|
60
|
+
if (!result.isValid) {
|
|
61
|
+
throw new UnauthenticatedError()
|
|
62
|
+
}
|
|
63
|
+
const user = await this.getUserStore().get(userName)
|
|
64
|
+
if (!user) {
|
|
65
|
+
throw new UnauthenticatedError()
|
|
70
66
|
}
|
|
71
|
-
|
|
67
|
+
return user
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
public async getCurrentUser(request: IncomingMessage) {
|
|
@@ -108,23 +104,16 @@ export class HttpUserContext {
|
|
|
108
104
|
// Cookie auth
|
|
109
105
|
const sessionId = this.getSessionIdFromRequest(request)
|
|
110
106
|
if (sessionId) {
|
|
111
|
-
const
|
|
107
|
+
const session = await this.getSessionStore().get(sessionId)
|
|
112
108
|
if (session) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
username: { $eq: session.username },
|
|
116
|
-
},
|
|
117
|
-
top: 2,
|
|
118
|
-
})
|
|
119
|
-
if (userResult.length === 1) {
|
|
120
|
-
const { password, ...user } = userResult[0]
|
|
109
|
+
const user = await this.getUserStore().get(session.username)
|
|
110
|
+
if (user) {
|
|
121
111
|
return user
|
|
122
112
|
}
|
|
123
|
-
throw Error('Inconsistent session result')
|
|
124
113
|
}
|
|
125
114
|
}
|
|
126
115
|
|
|
127
|
-
throw
|
|
116
|
+
throw new UnauthenticatedError()
|
|
128
117
|
}
|
|
129
118
|
|
|
130
119
|
/**
|
|
@@ -156,5 +145,6 @@ export class HttpUserContext {
|
|
|
156
145
|
constructor(
|
|
157
146
|
public readonly authentication: HttpAuthenticationSettings<User, DefaultSession>,
|
|
158
147
|
private readonly storeManager: StoreManager,
|
|
148
|
+
private readonly authenticator: PasswordAuthenticator,
|
|
159
149
|
) {}
|
|
160
150
|
}
|