@crombolo/auth 0.21.0 → 0.23.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/package.json +3 -3
- package/src/service.ts +11 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "OAuth2 authorization server, password hashing, cookies and member tickets for crombolo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.23.0",
|
|
32
|
+
"@crombolo/data": "0.23.0",
|
|
33
33
|
"jose": "^6.2.12",
|
|
34
34
|
"uqr": "^0.1.3"
|
|
35
35
|
}
|
package/src/service.ts
CHANGED
|
@@ -355,13 +355,21 @@ export class AuthService {
|
|
|
355
355
|
if (!token || token.revokedAt || token.expiresAt.getTime() < Date.now()) return undefined
|
|
356
356
|
const session = await this.#store.findSession(token.sessionId)
|
|
357
357
|
if (!session) return undefined
|
|
358
|
-
const
|
|
359
|
-
|
|
358
|
+
const identity = await this.identityOf(token.userId)
|
|
359
|
+
return identity && { ...identity, sessionId: token.sessionId }
|
|
360
|
+
}
|
|
360
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Who a user is and what they may do now, outside any session: for a
|
|
364
|
+
* credential that acts for them, such as a preview token. Undefined once they
|
|
365
|
+
* are locked out or not approved.
|
|
366
|
+
*/
|
|
367
|
+
async identityOf(userId: number): Promise<Omit<ResolvedIdentity, 'sessionId'> | undefined> {
|
|
368
|
+
const user = await this.#store.findUserById(userId)
|
|
369
|
+
if (!user || user.isLockedOut || !user.isApproved) return undefined
|
|
361
370
|
const authorization = await this.#store.loadAuthorization(user.id)
|
|
362
371
|
return {
|
|
363
372
|
user,
|
|
364
|
-
sessionId: token.sessionId,
|
|
365
373
|
allowedSections: toSectionAliases(authorization.appAliases),
|
|
366
374
|
groupKeys: authorization.groupKeys,
|
|
367
375
|
isAdmin: authorization.isAdmin,
|