@crombolo/auth 0.67.0 → 0.69.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/device.ts +15 -0
- package/src/service.ts +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.69.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. 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.69.0",
|
|
32
|
+
"@crombolo/data": "0.69.0",
|
|
33
33
|
"jose": "^6.2.12",
|
|
34
34
|
"uqr": "^0.1.3"
|
|
35
35
|
}
|
package/src/device.ts
CHANGED
|
@@ -138,6 +138,8 @@ export class DeviceStore {
|
|
|
138
138
|
userId: number
|
|
139
139
|
sessionId: string
|
|
140
140
|
expiresAt: Date
|
|
141
|
+
/** The tool the token named as acting for the person (story 366). */
|
|
142
|
+
actor?: { id: string; name: string | null }
|
|
141
143
|
}): Promise<void> {
|
|
142
144
|
const now = new Date()
|
|
143
145
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -153,6 +155,8 @@ export class DeviceStore {
|
|
|
153
155
|
status: 'issued',
|
|
154
156
|
user_id: init.userId,
|
|
155
157
|
session_id: init.sessionId,
|
|
158
|
+
actor_id: init.actor?.id ?? null,
|
|
159
|
+
actor_name: init.actor?.name ?? null,
|
|
156
160
|
interval_seconds: DEVICE_POLL_SECONDS,
|
|
157
161
|
expires_at: DbDate.toDb(init.expiresAt),
|
|
158
162
|
decided_at: DbDate.toDb(now),
|
|
@@ -166,6 +170,17 @@ export class DeviceStore {
|
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
|
|
173
|
+
/** The actor a device signed in by exchange was made for, by its session. */
|
|
174
|
+
async exchangeActor(sessionId: string): Promise<{ id: string; name: string | null } | undefined> {
|
|
175
|
+
const row = await this.#db.q
|
|
176
|
+
.selectFrom('device_authorization')
|
|
177
|
+
.select(['actor_id', 'actor_name'])
|
|
178
|
+
.where('session_id', '=', sessionId)
|
|
179
|
+
.where('actor_id', 'is not', null)
|
|
180
|
+
.executeTakeFirst()
|
|
181
|
+
return row?.actor_id ? { id: row.actor_id, name: row.actor_name } : undefined
|
|
182
|
+
}
|
|
183
|
+
|
|
169
184
|
async byDeviceCode(deviceCode: string): Promise<DeviceAuthorizationRow | undefined> {
|
|
170
185
|
const row = await this.#db.q
|
|
171
186
|
.selectFrom('device_authorization')
|
package/src/service.ts
CHANGED
|
@@ -103,6 +103,8 @@ export interface ResolvedIdentity {
|
|
|
103
103
|
sessionId: string
|
|
104
104
|
/** The provider a token exchanged through it came by (story 364); never set for a browser's session. */
|
|
105
105
|
exchangedThrough?: string
|
|
106
|
+
/** The tool acting for the person, as the exchanged token named it (story 366). */
|
|
107
|
+
exchangedActor?: { id: string; name: string | null }
|
|
106
108
|
allowedSections: Array<SectionAlias | ExtensionSectionAlias>
|
|
107
109
|
groupKeys: string[]
|
|
108
110
|
isAdmin: boolean
|
|
@@ -399,7 +401,10 @@ export class AuthService {
|
|
|
399
401
|
const own = await this.#store.loadAuthorization(user.id)
|
|
400
402
|
const view = session.view
|
|
401
403
|
const provider = exchangeProviderOf(token.clientId)
|
|
402
|
-
const
|
|
404
|
+
const actor = provider ? await this.#store.devices.exchangeActor(token.sessionId) : undefined
|
|
405
|
+
const through = provider
|
|
406
|
+
? { exchangedThrough: provider, ...(actor ? { exchangedActor: actor } : {}) }
|
|
407
|
+
: {}
|
|
403
408
|
if (view && view.until.getTime() > now.getTime() && own.isAdmin) {
|
|
404
409
|
const theirs = await this.#store.loadGroupAuthorization(view.groupKeys)
|
|
405
410
|
return {
|
|
@@ -549,6 +554,7 @@ export class AuthService {
|
|
|
549
554
|
provider: { id: string; name: string },
|
|
550
555
|
seconds: number,
|
|
551
556
|
ipAddress?: string,
|
|
557
|
+
actor?: { id: string; name: string | null },
|
|
552
558
|
): Promise<
|
|
553
559
|
| { status: 'success'; user: UserRow; accessToken: string; expiresIn: number }
|
|
554
560
|
| { status: 'notAllowed'; reason: 'lockedOut' | 'notApproved' | 'unknown' }
|
|
@@ -563,10 +569,11 @@ export class AuthService {
|
|
|
563
569
|
await this.#store.recordLoginSuccess(user.id, sessionId, ipAddress)
|
|
564
570
|
await this.#store.devices.signedInByExchange({
|
|
565
571
|
clientId,
|
|
566
|
-
clientName: `Signed in through ${provider.name}`,
|
|
572
|
+
clientName: `Signed in through ${provider.name}${actor ? `, by ${actor.name ?? actor.id}` : ''}`,
|
|
567
573
|
userId: user.id,
|
|
568
574
|
sessionId,
|
|
569
575
|
expiresAt,
|
|
576
|
+
actor,
|
|
570
577
|
})
|
|
571
578
|
const accessToken = generateToken()
|
|
572
579
|
await this.#store.createToken({
|