@ultimat3/auth 31.48.0 → 31.50.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/CLAUDE.md +10 -0
- package/README.md +98 -5
- package/package.json +5 -4
- package/src/adapter.ts +16 -0
- package/src/authorization-server-clients.ts +20 -10
- package/src/authorization-server-errors.ts +9 -0
- package/src/authorization-server-postgres-sql.ts +28 -4
- package/src/authorization-server-postgres.ts +6 -0
- package/src/authorization-server-register.ts +36 -10
- package/src/authorization-server-store.ts +67 -2
- package/src/authorization-server-tokens.ts +1 -0
- package/src/authorization-server-types.ts +33 -0
- package/src/authorization-server.ts +56 -2
- package/src/builtin-adapter.ts +2 -1
- package/src/client-scope.ts +4 -3
- package/src/errors.ts +6 -0
- package/src/grant-authorization-code.ts +7 -3
- package/src/identity-provider-route-core.ts +41 -8
- package/src/identity-provider-routes.ts +1 -0
- package/src/index.ts +12 -0
- package/src/memory-adapter.ts +2 -1
- package/src/mfa-handoff.ts +92 -0
- package/src/oauth-route.ts +9 -0
- package/src/passkey-config.ts +9 -0
- package/src/passkey-errors.ts +22 -0
- package/src/passkey-label.ts +52 -0
- package/src/passkey-memory.ts +19 -2
- package/src/passkey-postgres.ts +13 -3
- package/src/tables.ts +9 -1
- package/src/verify.ts +11 -0
package/src/passkey-postgres.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
} from './adapter';
|
|
13
13
|
import { usersUniqueViolation } from './builtin-adapter-violation';
|
|
14
14
|
import { authWriteFailed } from './errors';
|
|
15
|
+
import { passkeyLabel } from './passkey-label';
|
|
15
16
|
|
|
16
17
|
type Row = Readonly<Record<string, unknown>>;
|
|
17
18
|
|
|
@@ -49,6 +50,8 @@ const toCredential = (row: Row): PasskeyCredential => ({
|
|
|
49
50
|
transports: strings(row, 'transports'),
|
|
50
51
|
createdAt: when(row, 'created_at') ?? new Date(0),
|
|
51
52
|
lastUsedAt: when(row, 'last_used_at'),
|
|
53
|
+
// Absent for none, as the memory store reads: a label is the one optional field of the row.
|
|
54
|
+
...(strOrNull(row, 'label') === null ? {} : { label: str(row, 'label') }),
|
|
52
55
|
});
|
|
53
56
|
|
|
54
57
|
const toChallenge = (row: Row, ceremony: PasskeyCeremony): PasskeyChallengeRecord => ({
|
|
@@ -78,17 +81,17 @@ const toEvidence = (row: Row): PasskeyEvidence => ({
|
|
|
78
81
|
});
|
|
79
82
|
|
|
80
83
|
/** The members, over a client resolved per call — the adapter's ambient `db()` rule. */
|
|
81
|
-
export function postgresPasskeyStore(client: () => DbClient): PasskeyStore {
|
|
84
|
+
export function postgresPasskeyStore(client: () => DbClient): Required<PasskeyStore> {
|
|
82
85
|
return {
|
|
83
86
|
async putPasskey(credential) {
|
|
84
87
|
let row: Row | null;
|
|
85
88
|
try {
|
|
86
89
|
row = await client().one<Row>(sql`
|
|
87
90
|
insert into x_passkeys (id, user_id, public_key, algorithm, sign_count, transports,
|
|
88
|
-
created_at)
|
|
91
|
+
created_at, label)
|
|
89
92
|
values (${credential.id}, ${credential.userId}, ${credential.publicKey},
|
|
90
93
|
${credential.algorithm}, ${credential.signCount}, ${[...credential.transports]},
|
|
91
|
-
${credential.createdAt})
|
|
94
|
+
${credential.createdAt}, ${passkeyLabel(credential.label)})
|
|
92
95
|
returning *`);
|
|
93
96
|
} catch (error) {
|
|
94
97
|
throw usersUniqueViolation('putPasskey', error) ?? error;
|
|
@@ -112,6 +115,13 @@ export function postgresPasskeyStore(client: () => DbClient): PasskeyStore {
|
|
|
112
115
|
returning id`);
|
|
113
116
|
return row !== null;
|
|
114
117
|
},
|
|
118
|
+
async renamePasskey(userId, id, label) {
|
|
119
|
+
const row = await client().one<Row>(sql`
|
|
120
|
+
update x_passkeys set label = ${label}
|
|
121
|
+
where id = ${id} and user_id = ${userId}
|
|
122
|
+
returning *`);
|
|
123
|
+
return row === null ? null : toCredential(row);
|
|
124
|
+
},
|
|
115
125
|
async deletePasskey(userId, id) {
|
|
116
126
|
const removed = await client().execute(
|
|
117
127
|
sql`delete from x_passkeys where id = ${id} and user_id = ${userId}`,
|
package/src/tables.ts
CHANGED
|
@@ -128,10 +128,17 @@ const X_PASSKEYS_TABLE = `create table if not exists x_passkeys (
|
|
|
128
128
|
sign_count bigint not null default 0,
|
|
129
129
|
transports text[] not null default '{}',
|
|
130
130
|
created_at timestamptz not null default now(),
|
|
131
|
-
last_used_at timestamptz
|
|
131
|
+
last_used_at timestamptz,
|
|
132
|
+
label text
|
|
132
133
|
);
|
|
133
134
|
create index if not exists x_passkeys_user_id_idx on x_passkeys (user_id)`;
|
|
134
135
|
|
|
136
|
+
/**
|
|
137
|
+
* What `x_passkeys` gained with passkey labels, applied at every boot right after the create, on
|
|
138
|
+
* `X_USERS_UPGRADE`'s rule: idempotent, additive, nullable — a catalog update on a live table.
|
|
139
|
+
*/
|
|
140
|
+
const X_PASSKEYS_UPGRADE = 'alter table x_passkeys add column if not exists label text';
|
|
141
|
+
|
|
135
142
|
const X_PASSKEY_CHALLENGES_TABLE = `create table if not exists x_passkey_challenges (
|
|
136
143
|
id text primary key,
|
|
137
144
|
ceremony text not null,
|
|
@@ -167,6 +174,7 @@ export const AUTH_TABLES: readonly string[] = Object.freeze([
|
|
|
167
174
|
X_VERIFICATIONS_TABLE,
|
|
168
175
|
X_API_KEYS_TABLE,
|
|
169
176
|
X_PASSKEYS_TABLE,
|
|
177
|
+
X_PASSKEYS_UPGRADE,
|
|
170
178
|
X_PASSKEY_CHALLENGES_TABLE,
|
|
171
179
|
X_PASSKEY_EVIDENCE_TABLE,
|
|
172
180
|
]);
|
package/src/verify.ts
CHANGED
|
@@ -147,6 +147,17 @@ export interface ConsumeVerificationInput {
|
|
|
147
147
|
export async function consumeVerification(
|
|
148
148
|
runtime: VerificationRuntime,
|
|
149
149
|
input: ConsumeVerificationInput,
|
|
150
|
+
): Promise<AuthVerification> {
|
|
151
|
+
return consumeWith(runtime, input);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* `consumeVerification` without the mailer: consuming sends nothing, so a caller with no mailer in
|
|
156
|
+
* hand (`signInWithLink`) needs none. Internal, so the exported signature stays as it shipped.
|
|
157
|
+
*/
|
|
158
|
+
export async function consumeWith(
|
|
159
|
+
runtime: Pick<VerificationRuntime, 'store' | 'clock'>,
|
|
160
|
+
input: ConsumeVerificationInput,
|
|
150
161
|
): Promise<AuthVerification> {
|
|
151
162
|
const purpose = verificationPurpose(input.purpose);
|
|
152
163
|
const tokenHash = sha256Hex(input.token);
|