@pithy-sh/auth 0.15.3 → 0.16.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/README.md +4 -0
- package/dist/attestation/appAttest/assertion.d.ts +32 -0
- package/dist/attestation/appAttest/assertion.d.ts.map +1 -0
- package/dist/attestation/appAttest/assertion.js +59 -0
- package/dist/attestation/appAttest/attestation.d.ts +49 -0
- package/dist/attestation/appAttest/attestation.d.ts.map +1 -0
- package/dist/attestation/appAttest/attestation.js +111 -0
- package/dist/attestation/appAttest/authData.d.ts +24 -0
- package/dist/attestation/appAttest/authData.d.ts.map +1 -0
- package/dist/attestation/appAttest/authData.js +32 -0
- package/dist/attestation/appAttest/base64.d.ts +8 -0
- package/dist/attestation/appAttest/base64.d.ts.map +1 -0
- package/dist/attestation/appAttest/base64.js +27 -0
- package/dist/attestation/appAttest/bytes.d.ts +7 -0
- package/dist/attestation/appAttest/bytes.d.ts.map +1 -0
- package/dist/attestation/appAttest/bytes.js +19 -0
- package/dist/attestation/appAttest/cbor.d.ts +20 -0
- package/dist/attestation/appAttest/cbor.d.ts.map +1 -0
- package/dist/attestation/appAttest/cbor.js +96 -0
- package/dist/attestation/appAttest/der.d.ts +38 -0
- package/dist/attestation/appAttest/der.d.ts.map +1 -0
- package/dist/attestation/appAttest/der.js +106 -0
- package/dist/attestation/appAttest/keys.d.ts +15 -0
- package/dist/attestation/appAttest/keys.d.ts.map +1 -0
- package/dist/attestation/appAttest/keys.js +37 -0
- package/dist/attestation/appAttest/root.d.ts +9 -0
- package/dist/attestation/appAttest/root.d.ts.map +1 -0
- package/dist/attestation/appAttest/root.js +12 -0
- package/dist/attestation/appAttest/verifier.d.ts +39 -0
- package/dist/attestation/appAttest/verifier.d.ts.map +1 -0
- package/dist/attestation/appAttest/verifier.js +121 -0
- package/dist/attestation/appAttest/x509.d.ts +50 -0
- package/dist/attestation/appAttest/x509.d.ts.map +1 -0
- package/dist/attestation/appAttest/x509.js +163 -0
- package/dist/attestation/challenge.d.ts +26 -0
- package/dist/attestation/challenge.d.ts.map +1 -0
- package/dist/attestation/challenge.js +47 -0
- package/dist/attestation/config.d.ts +72 -0
- package/dist/attestation/config.d.ts.map +1 -0
- package/dist/attestation/config.js +52 -0
- package/dist/attestation/errors.d.ts +30 -0
- package/dist/attestation/errors.d.ts.map +1 -0
- package/dist/attestation/errors.js +45 -0
- package/dist/attestation/gate.d.ts +27 -0
- package/dist/attestation/gate.d.ts.map +1 -0
- package/dist/attestation/gate.js +78 -0
- package/dist/attestation/playIntegrity/google.d.ts +47 -0
- package/dist/attestation/playIntegrity/google.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/google.js +178 -0
- package/dist/attestation/playIntegrity/verdict.d.ts +40 -0
- package/dist/attestation/playIntegrity/verdict.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verdict.js +93 -0
- package/dist/attestation/playIntegrity/verifier.d.ts +22 -0
- package/dist/attestation/playIntegrity/verifier.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verifier.js +64 -0
- package/dist/attestation/verifier.d.ts +60 -0
- package/dist/attestation/verifier.d.ts.map +1 -0
- package/dist/attestation/verifier.js +46 -0
- package/dist/attestation/wire.d.ts +42 -0
- package/dist/attestation/wire.d.ts.map +1 -0
- package/dist/attestation/wire.js +72 -0
- package/dist/capability.d.ts +40 -0
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +38 -5
- package/dist/client/api.d.ts +37 -24
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +52 -41
- package/dist/client/attestation.d.ts +148 -0
- package/dist/client/attestation.d.ts.map +1 -0
- package/dist/client/attestation.js +321 -0
- package/dist/client/projection.d.ts +29 -4
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/appAttestKey.d.ts +30 -0
- package/dist/data/appAttestKey.d.ts.map +1 -0
- package/dist/data/appAttestKey.js +25 -0
- package/dist/data/attestationChallenge.d.ts +17 -0
- package/dist/data/attestationChallenge.d.ts.map +1 -0
- package/dist/data/attestationChallenge.js +19 -0
- package/dist/data/tables.d.ts +18 -1
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +6 -2
- package/dist/http/devLoginRoute.js +3 -3
- package/dist/http/resolve.js +1 -1
- package/dist/http/responses.d.ts +12 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +11 -1
- package/dist/http/routes.d.ts +5 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +92 -25
- package/dist/http/schemas.d.ts +7 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +7 -1
- package/dist/index.js +1 -1
- package/dist/instance/secrets.d.ts +86 -7
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +54 -8
- package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
- package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
- package/dist/migrations/0009_attestation_challenges.js +21 -0
- package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
- package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
- package/dist/migrations/0010_app_attest_keys.js +17 -0
- package/dist/migrations/set.d.ts +3 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +6 -2
- package/dist/seeds/devSession.js +1 -1
- package/dist/test-utils/appAttestDevice.d.ts +92 -0
- package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
- package/dist/test-utils/appAttestDevice.js +282 -0
- package/dist/test-utils/appAttestSample.d.ts +22 -0
- package/dist/test-utils/appAttestSample.d.ts.map +1 -0
- package/dist/test-utils/appAttestSample.js +24 -0
- package/dist/test-utils/googlePlay.d.ts +47 -0
- package/dist/test-utils/googlePlay.d.ts.map +1 -0
- package/dist/test-utils/googlePlay.js +117 -0
- package/dist/test-utils/liveApp.d.ts +76 -36
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +16 -5
- package/dist/test-utils/rollbackThrough.d.ts +11 -0
- package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
- package/dist/test-utils/rollbackThrough.js +16 -0
- package/dist/test-utils/scopedBackend.d.ts +25 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/attestation.md +173 -0
- package/package.json +5 -5
- package/pithy.manifest.json +14 -0
- package/src/attestation/appAttest/assertion.ts +65 -0
- package/src/attestation/appAttest/attestation.ts +159 -0
- package/src/attestation/appAttest/authData.ts +45 -0
- package/src/attestation/appAttest/base64.ts +29 -0
- package/src/attestation/appAttest/bytes.ts +18 -0
- package/src/attestation/appAttest/cbor.ts +116 -0
- package/src/attestation/appAttest/der.ts +126 -0
- package/src/attestation/appAttest/keys.ts +57 -0
- package/src/attestation/appAttest/root.ts +13 -0
- package/src/attestation/appAttest/verifier.ts +113 -0
- package/src/attestation/appAttest/x509.ts +209 -0
- package/src/attestation/challenge.ts +56 -0
- package/src/attestation/config.ts +118 -0
- package/src/attestation/errors.ts +60 -0
- package/src/attestation/gate.ts +105 -0
- package/src/attestation/playIntegrity/google.ts +239 -0
- package/src/attestation/playIntegrity/verdict.ts +149 -0
- package/src/attestation/playIntegrity/verifier.ts +77 -0
- package/src/attestation/verifier.ts +87 -0
- package/src/attestation/wire.ts +79 -0
- package/src/capability.ts +64 -8
- package/src/client/api.ts +73 -40
- package/src/client/attestation.ts +404 -0
- package/src/client/projection.ts +29 -4
- package/src/data/appAttestKey.ts +45 -0
- package/src/data/attestationChallenge.ts +23 -0
- package/src/data/tables.ts +5 -1
- package/src/http/responses.ts +22 -0
- package/src/http/routes.ts +128 -38
- package/src/http/schemas.ts +24 -0
- package/src/instance/secrets.ts +88 -9
- package/src/migrations/0009_attestation_challenges.ts +28 -0
- package/src/migrations/0010_app_attest_keys.ts +27 -0
- package/src/migrations/set.ts +5 -1
- package/src/test-utils/appAttestDevice.ts +399 -0
- package/src/test-utils/appAttestSample.ts +20 -0
- package/src/test-utils/googlePlay.ts +144 -0
- package/src/test-utils/liveApp.ts +31 -5
- package/src/test-utils/rollbackThrough.ts +24 -0
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { base64UrlDecode, base64UrlEncode } from "@pithy-sh/core/src/controlPlane/token/base64url";
|
|
4
|
+
//#region src/test-utils/googlePlay.ts
|
|
5
|
+
function pem(der) {
|
|
6
|
+
return `-----BEGIN PRIVATE KEY-----\n${(btoa(String.fromCharCode(...new Uint8Array(der))).match(/.{1,64}/g) ?? []).join("\n")}\n-----END PRIVATE KEY-----\n`;
|
|
7
|
+
}
|
|
8
|
+
/** Make a service account whose `private_key` is a fresh RSA-2048 PKCS#8 PEM. */
|
|
9
|
+
async function testServiceAccount() {
|
|
10
|
+
const pair = await crypto.subtle.generateKey({
|
|
11
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
12
|
+
modulusLength: 2048,
|
|
13
|
+
publicExponent: new Uint8Array([
|
|
14
|
+
1,
|
|
15
|
+
0,
|
|
16
|
+
1
|
|
17
|
+
]),
|
|
18
|
+
hash: "SHA-256"
|
|
19
|
+
}, true, ["sign", "verify"]);
|
|
20
|
+
return {
|
|
21
|
+
account: {
|
|
22
|
+
type: "service_account",
|
|
23
|
+
project_id: "example-project",
|
|
24
|
+
private_key_id: "0123456789abcdef",
|
|
25
|
+
private_key: pem(await crypto.subtle.exportKey("pkcs8", pair.privateKey)),
|
|
26
|
+
client_email: "play-integrity@example-project.iam.gserviceaccount.com",
|
|
27
|
+
client_id: "1234567890",
|
|
28
|
+
token_uri: "https://oauth2.googleapis.com/token"
|
|
29
|
+
},
|
|
30
|
+
publicKey: pair.publicKey
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A JWT's three parts, decoded, and whether its RS256 signature verifies with `publicKey`. */
|
|
34
|
+
async function readJwt(jwt, publicKey) {
|
|
35
|
+
const [header = "", claims = "", signature = ""] = jwt.split(".");
|
|
36
|
+
const decode = (part) => JSON.parse(new TextDecoder().decode(base64UrlDecode(part)));
|
|
37
|
+
const verified = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, base64UrlDecode(signature), new TextEncoder().encode(`${header}.${claims}`));
|
|
38
|
+
return {
|
|
39
|
+
header: decode(header),
|
|
40
|
+
claims: decode(claims),
|
|
41
|
+
verified
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A `fetch` that answers Google's token endpoint and `decodeIntegrityToken`, from the answers it is handed, and
|
|
46
|
+
* records every request. Any other URL is a test fault and throws.
|
|
47
|
+
*/
|
|
48
|
+
function googleFetch(answers) {
|
|
49
|
+
const seen = [];
|
|
50
|
+
const respond = (answer) => new Response(JSON.stringify(answer.body), {
|
|
51
|
+
status: answer.status,
|
|
52
|
+
headers: { "content-type": "application/json" }
|
|
53
|
+
});
|
|
54
|
+
const stub = async (input, init) => {
|
|
55
|
+
const request = new Request(input, init);
|
|
56
|
+
const record = {
|
|
57
|
+
url: request.url,
|
|
58
|
+
method: request.method,
|
|
59
|
+
headers: request.headers,
|
|
60
|
+
body: await request.text()
|
|
61
|
+
};
|
|
62
|
+
seen.push(record);
|
|
63
|
+
if (record.url === "https://oauth2.googleapis.com/token") {
|
|
64
|
+
const answer = answers.token ?? {
|
|
65
|
+
status: 200,
|
|
66
|
+
body: {
|
|
67
|
+
access_token: "ya29.test",
|
|
68
|
+
expires_in: 3599
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return respond(typeof answer === "function" ? await answer() : answer);
|
|
72
|
+
}
|
|
73
|
+
if (record.url.startsWith("https://playintegrity.googleapis.com/v1/")) {
|
|
74
|
+
const answer = answers.decode ?? {
|
|
75
|
+
status: 500,
|
|
76
|
+
body: {}
|
|
77
|
+
};
|
|
78
|
+
return respond(typeof answer === "function" ? await answer(record) : answer);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`googleFetch: no stub for ${record.url}`);
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
fetch: stub,
|
|
84
|
+
seen
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** A `decodeIntegrityToken` answer that passes, bound to `binding`, as Google records it for a standard request. */
|
|
88
|
+
function passingDecode(binding, now, packageName = "com.example.app") {
|
|
89
|
+
return passingDecodeOf(base64UrlEncode(binding), now, packageName);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A `decodeIntegrityToken` answer that passes, carrying `requestHash` exactly as the app handed it to Play Integrity:
|
|
93
|
+
* Google records the string it was given, so the Worker compares the client's own characters.
|
|
94
|
+
*/
|
|
95
|
+
function passingDecodeOf(requestHash, now, packageName = "com.example.app") {
|
|
96
|
+
return {
|
|
97
|
+
status: 200,
|
|
98
|
+
body: { tokenPayloadExternal: {
|
|
99
|
+
requestDetails: {
|
|
100
|
+
requestPackageName: packageName,
|
|
101
|
+
requestHash,
|
|
102
|
+
timestampMillis: String(now.getTime() - 1500)
|
|
103
|
+
},
|
|
104
|
+
appIntegrity: {
|
|
105
|
+
appRecognitionVerdict: "PLAY_RECOGNIZED",
|
|
106
|
+
packageName,
|
|
107
|
+
certificateSha256Digest: ["6a6a1474b5cbbb2b1aa57e0bc3"],
|
|
108
|
+
versionCode: "42"
|
|
109
|
+
},
|
|
110
|
+
deviceIntegrity: { deviceRecognitionVerdict: ["MEETS_DEVICE_INTEGRITY"] },
|
|
111
|
+
accountDetails: { appLicensingVerdict: "LICENSED" },
|
|
112
|
+
environmentDetails: { playProtectVerdict: "NO_ISSUES" }
|
|
113
|
+
} }
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { googleFetch, passingDecode, passingDecodeOf, readJwt, testServiceAccount };
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
4
|
import type { AuditEventInput } from "@pithy-sh/core/src/audit/auditEvent";
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
import type { AttestationConfig } from "../attestation/config";
|
|
7
|
+
import { type PlayIntegrityServiceAccount } from "../instance/secrets";
|
|
5
8
|
/**
|
|
6
|
-
* A real auth Worker on a real port, for the live suites
|
|
9
|
+
* A real auth Worker on a real port, for the live suites.
|
|
7
10
|
*
|
|
8
11
|
* The live E2E questions this package has are about an **origin**: which `redirect_uri` Better Auth
|
|
9
12
|
* hands Google, whether a token posted from a browser survives the humanity gate, whether a callback
|
|
@@ -17,7 +20,7 @@ import type { AuditEventInput } from "@pithy-sh/core/src/audit/auditEvent";
|
|
|
17
20
|
*
|
|
18
21
|
* - **Miniflare supplies D1**, from Node rather than from inside a worker. Two databases, as a deployed
|
|
19
22
|
* worker has: `DB` for the `pithy_auth_*` and `pithy_email_*` tables, `SECRETS` for the encrypted
|
|
20
|
-
* rows every secret is read from
|
|
23
|
+
* rows every secret is read from. No plaintext binding stands in for either.
|
|
21
24
|
* - **The migrations are the real ones**, run through the real registry and runner.
|
|
22
25
|
* - **`node:http` gives the port.** Vitest's `fetch` reaches the app the way a browser would, so an
|
|
23
26
|
* `Origin` header is a real one and a `Set-Cookie` is a real one.
|
|
@@ -55,10 +58,10 @@ export declare const LIVE_REGISTRY: {
|
|
|
55
58
|
readonly scope: "environment";
|
|
56
59
|
readonly rotatable: false;
|
|
57
60
|
readonly valueType: "json";
|
|
58
|
-
readonly schema:
|
|
59
|
-
clientId:
|
|
60
|
-
clientSecret:
|
|
61
|
-
},
|
|
61
|
+
readonly schema: z.ZodObject<{
|
|
62
|
+
clientId: z.ZodString;
|
|
63
|
+
clientSecret: z.ZodString;
|
|
64
|
+
}, z.core.$strip>;
|
|
62
65
|
readonly origin: {
|
|
63
66
|
readonly kind: "obtained";
|
|
64
67
|
readonly issuer: "google";
|
|
@@ -75,11 +78,11 @@ export declare const LIVE_REGISTRY: {
|
|
|
75
78
|
readonly scope: "environment";
|
|
76
79
|
readonly rotatable: true;
|
|
77
80
|
readonly valueType: "json";
|
|
78
|
-
readonly schema:
|
|
79
|
-
clientId:
|
|
80
|
-
clientSecret:
|
|
81
|
-
appBundleIdentifier:
|
|
82
|
-
},
|
|
81
|
+
readonly schema: z.ZodObject<{
|
|
82
|
+
clientId: z.ZodString;
|
|
83
|
+
clientSecret: z.ZodString;
|
|
84
|
+
appBundleIdentifier: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$strip>;
|
|
83
86
|
readonly origin: {
|
|
84
87
|
readonly kind: "obtained";
|
|
85
88
|
readonly issuer: "apple";
|
|
@@ -96,10 +99,10 @@ export declare const LIVE_REGISTRY: {
|
|
|
96
99
|
readonly scope: "environment";
|
|
97
100
|
readonly rotatable: false;
|
|
98
101
|
readonly valueType: "json";
|
|
99
|
-
readonly schema:
|
|
100
|
-
clientId:
|
|
101
|
-
clientSecret:
|
|
102
|
-
},
|
|
102
|
+
readonly schema: z.ZodObject<{
|
|
103
|
+
clientId: z.ZodString;
|
|
104
|
+
clientSecret: z.ZodString;
|
|
105
|
+
}, z.core.$strip>;
|
|
103
106
|
readonly origin: {
|
|
104
107
|
readonly kind: "obtained";
|
|
105
108
|
readonly issuer: "facebook";
|
|
@@ -116,10 +119,10 @@ export declare const LIVE_REGISTRY: {
|
|
|
116
119
|
readonly scope: "environment";
|
|
117
120
|
readonly rotatable: false;
|
|
118
121
|
readonly valueType: "json";
|
|
119
|
-
readonly schema:
|
|
120
|
-
clientId:
|
|
121
|
-
clientSecret:
|
|
122
|
-
},
|
|
122
|
+
readonly schema: z.ZodObject<{
|
|
123
|
+
clientId: z.ZodString;
|
|
124
|
+
clientSecret: z.ZodString;
|
|
125
|
+
}, z.core.$strip>;
|
|
123
126
|
readonly origin: {
|
|
124
127
|
readonly kind: "obtained";
|
|
125
128
|
readonly issuer: "github";
|
|
@@ -136,11 +139,11 @@ export declare const LIVE_REGISTRY: {
|
|
|
136
139
|
readonly scope: "environment";
|
|
137
140
|
readonly rotatable: true;
|
|
138
141
|
readonly valueType: "json";
|
|
139
|
-
readonly schema:
|
|
140
|
-
clientId:
|
|
141
|
-
clientSecret:
|
|
142
|
-
tenantId:
|
|
143
|
-
},
|
|
142
|
+
readonly schema: z.ZodObject<{
|
|
143
|
+
clientId: z.ZodString;
|
|
144
|
+
clientSecret: z.ZodString;
|
|
145
|
+
tenantId: z.ZodString;
|
|
146
|
+
}, z.core.$strip>;
|
|
144
147
|
readonly origin: {
|
|
145
148
|
readonly kind: "obtained";
|
|
146
149
|
readonly issuer: "microsoft";
|
|
@@ -152,21 +155,46 @@ export declare const LIVE_REGISTRY: {
|
|
|
152
155
|
readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
|
|
153
156
|
};
|
|
154
157
|
};
|
|
158
|
+
"auth-play-integrity-service-account": {
|
|
159
|
+
readonly backend: "d1";
|
|
160
|
+
readonly scope: "environment";
|
|
161
|
+
readonly rotatable: false;
|
|
162
|
+
readonly valueType: "json";
|
|
163
|
+
readonly schema: z.ZodObject<{
|
|
164
|
+
type: z.ZodOptional<z.ZodLiteral<"service_account">>;
|
|
165
|
+
project_id: z.ZodOptional<z.ZodString>;
|
|
166
|
+
private_key_id: z.ZodOptional<z.ZodString>;
|
|
167
|
+
private_key: z.ZodString;
|
|
168
|
+
client_email: z.ZodString;
|
|
169
|
+
client_id: z.ZodOptional<z.ZodString>;
|
|
170
|
+
token_uri: z.ZodOptional<z.ZodString>;
|
|
171
|
+
}, z.core.$strip>;
|
|
172
|
+
readonly origin: {
|
|
173
|
+
readonly kind: "obtained";
|
|
174
|
+
readonly issuer: "google";
|
|
175
|
+
readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
|
|
176
|
+
};
|
|
177
|
+
readonly rotation: {
|
|
178
|
+
readonly kind: "manual";
|
|
179
|
+
readonly issuer: "google";
|
|
180
|
+
readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
|
|
181
|
+
};
|
|
182
|
+
};
|
|
155
183
|
"turnstile-secret-keys": {
|
|
156
184
|
readonly backend: "d1";
|
|
157
185
|
readonly scope: "environment";
|
|
158
186
|
readonly rotatable: true;
|
|
159
187
|
readonly valueType: "json";
|
|
160
|
-
readonly schema:
|
|
161
|
-
visible:
|
|
162
|
-
key:
|
|
163
|
-
lastRotatedAt:
|
|
164
|
-
},
|
|
165
|
-
invisible:
|
|
166
|
-
key:
|
|
167
|
-
lastRotatedAt:
|
|
168
|
-
},
|
|
169
|
-
},
|
|
188
|
+
readonly schema: z.ZodObject<{
|
|
189
|
+
visible: z.ZodOptional<z.ZodObject<{
|
|
190
|
+
key: z.ZodString;
|
|
191
|
+
lastRotatedAt: z.ZodOptional<z.ZodString>;
|
|
192
|
+
}, z.core.$strip>>;
|
|
193
|
+
invisible: z.ZodOptional<z.ZodObject<{
|
|
194
|
+
key: z.ZodString;
|
|
195
|
+
lastRotatedAt: z.ZodOptional<z.ZodString>;
|
|
196
|
+
}, z.core.$strip>>;
|
|
197
|
+
}, z.core.$strict>;
|
|
170
198
|
readonly origin: {
|
|
171
199
|
readonly kind: "obtained";
|
|
172
200
|
readonly issuer: "cloudflare";
|
|
@@ -214,10 +242,22 @@ export interface LiveAppOptions {
|
|
|
214
242
|
* stanza. `dev` by default, because that is what these suites are: a developer's machine, running the
|
|
215
243
|
* stack the way `pithy dev` does.
|
|
216
244
|
*
|
|
217
|
-
* It is an option because
|
|
218
|
-
* outside dev and staging
|
|
245
|
+
* It is an option because the turnstile gate refuses a Cloudflare test key
|
|
246
|
+
* outside dev and staging — so a suite has to be able to say it is prod to prove that.
|
|
219
247
|
*/
|
|
220
248
|
environment?: string;
|
|
249
|
+
/** Auth's `attestation` block, as `auth()` takes it. Absent, attestation is not configured. */
|
|
250
|
+
attestation?: z.input<typeof AttestationConfig>;
|
|
251
|
+
/** The root an App Attest key's chain must lead to, DER, in place of Apple's: a test device's. */
|
|
252
|
+
appAttestRoot?: Uint8Array;
|
|
253
|
+
/**
|
|
254
|
+
* Play Integrity's service account, stored as auth's secret, and the `fetch` the verifier calls Google with: a
|
|
255
|
+
* stand-in for Google's token endpoint and `decodeIntegrityToken`, so Google is the one thing not live.
|
|
256
|
+
*/
|
|
257
|
+
playIntegrity?: {
|
|
258
|
+
account: PlayIntegrityServiceAccount;
|
|
259
|
+
fetch: typeof fetch;
|
|
260
|
+
} | undefined;
|
|
221
261
|
}
|
|
222
262
|
/** A booted app: where it listens, what it was pinned to, and what it recorded. */
|
|
223
263
|
export interface LiveApp {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveApp.d.ts","sourceRoot":"","sources":["../../src/test-utils/liveApp.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"liveApp.d.ts","sourceRoot":"","sources":["../../src/test-utils/liveApp.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAc3E,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAQ/D,OAAO,EAAuB,KAAK,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAI5F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,iHAAiH;AACjH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AO,CAAC,aAAa,EAAE,CAAC,CAAC;IACrC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C;;;OAGG;IACH,EAAE,EAAE,UAAU,CAAC;IACf,yFAAyF;IACzF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAuG5E"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
import { publishSameOrigin } from "../http/csrf.js";
|
|
4
3
|
import { authSecretsRegistry } from "../instance/secrets.js";
|
|
4
|
+
import { createPlayIntegrityVerifier } from "../attestation/playIntegrity/verifier.js";
|
|
5
|
+
import { PLATFORM_VERIFIERS } from "../attestation/verifier.js";
|
|
6
|
+
import { publishSameOrigin } from "../http/csrf.js";
|
|
5
7
|
import { createSessionMiddleware } from "../http/middleware.js";
|
|
6
8
|
import { createRateLimitMiddleware } from "../http/rateLimit.js";
|
|
7
9
|
import { createAuthRoutes } from "../http/routes.js";
|
|
@@ -22,7 +24,7 @@ import { Hono } from "hono";
|
|
|
22
24
|
import { Miniflare, convertV4MiniflareOptions } from "miniflare";
|
|
23
25
|
//#region src/test-utils/liveApp.ts
|
|
24
26
|
/**
|
|
25
|
-
* A real auth Worker on a real port, for the live suites
|
|
27
|
+
* A real auth Worker on a real port, for the live suites.
|
|
26
28
|
*
|
|
27
29
|
* The live E2E questions this package has are about an **origin**: which `redirect_uri` Better Auth
|
|
28
30
|
* hands Google, whether a token posted from a browser survives the humanity gate, whether a callback
|
|
@@ -36,7 +38,7 @@ import { Miniflare, convertV4MiniflareOptions } from "miniflare";
|
|
|
36
38
|
*
|
|
37
39
|
* - **Miniflare supplies D1**, from Node rather than from inside a worker. Two databases, as a deployed
|
|
38
40
|
* worker has: `DB` for the `pithy_auth_*` and `pithy_email_*` tables, `SECRETS` for the encrypted
|
|
39
|
-
* rows every secret is read from
|
|
41
|
+
* rows every secret is read from. No plaintext binding stands in for either.
|
|
40
42
|
* - **The migrations are the real ones**, run through the real registry and runner.
|
|
41
43
|
* - **`node:http` gives the port.** Vitest's `fetch` reaches the app the way a browser would, so an
|
|
42
44
|
* `Origin` header is a real one and a `Set-Cookie` is a real one.
|
|
@@ -56,6 +58,8 @@ function resetLiveSecrets() {
|
|
|
56
58
|
/** Tables the app database holds once both capabilities' migrations have run. */
|
|
57
59
|
const TABLES = [
|
|
58
60
|
"pithy_auth_accounts",
|
|
61
|
+
"pithy_auth_app_attest_keys",
|
|
62
|
+
"pithy_auth_attestation_challenges",
|
|
59
63
|
"pithy_auth_devices",
|
|
60
64
|
"pithy_auth_jwks",
|
|
61
65
|
"pithy_auth_rate_limit",
|
|
@@ -101,6 +105,7 @@ async function startLiveApp(options) {
|
|
|
101
105
|
await migrate(db);
|
|
102
106
|
const fixture = { "auth-session-secret": SESSION_SECRET };
|
|
103
107
|
if (options.google) fixture["auth-google-credentials"] = options.google;
|
|
108
|
+
if (options.playIntegrity) fixture["auth-play-integrity-service-account"] = options.playIntegrity.account;
|
|
104
109
|
if (options.turnstile) fixture["turnstile-secret-keys"] = { [options.turnstile.mode]: { key: options.turnstile.secretKey } };
|
|
105
110
|
configureSharedSecrets({ registry: LIVE_REGISTRY });
|
|
106
111
|
await seedSecrets(env, LIVE_REGISTRY, fixture);
|
|
@@ -117,14 +122,20 @@ async function startLiveApp(options) {
|
|
|
117
122
|
baseURL: origin,
|
|
118
123
|
basePath: options.basePath,
|
|
119
124
|
trustedOrigins: [origin],
|
|
120
|
-
google: { enabled: Boolean(options.google) }
|
|
125
|
+
google: { enabled: Boolean(options.google) },
|
|
126
|
+
...options.attestation ? { attestation: options.attestation } : {}
|
|
121
127
|
}),
|
|
122
128
|
resolveGithubUserInfo: void 0,
|
|
123
129
|
enqueueEmail: emailCapability.enqueue,
|
|
124
130
|
turnstile: options.turnstile ? {
|
|
125
131
|
mode: options.turnstile.mode,
|
|
126
132
|
token: { field: "cf-turnstile-response" }
|
|
127
|
-
} : void 0
|
|
133
|
+
} : void 0,
|
|
134
|
+
appAttestRoot: options.appAttestRoot,
|
|
135
|
+
...options.playIntegrity ? { attestationVerifiers: {
|
|
136
|
+
...PLATFORM_VERIFIERS,
|
|
137
|
+
android: createPlayIntegrityVerifier({ fetch: options.playIntegrity.fetch })
|
|
138
|
+
} } : {}
|
|
128
139
|
}, events);
|
|
129
140
|
server.on("request", (request, response) => {
|
|
130
141
|
serve(app, env, origin, request, response);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
|
+
import type { MigrationProvider } from "kysely/migration";
|
|
5
|
+
import type { AUTH_MIGRATIONS } from "../migrations/set";
|
|
6
|
+
/**
|
|
7
|
+
* Roll the auth chain back until `key` is no longer applied, so a migration's own `down` is reached however many
|
|
8
|
+
* migrations were appended after it. Throws when `key` was never applied.
|
|
9
|
+
*/
|
|
10
|
+
export declare function rollbackThrough(d1: D1Database, provider: MigrationProvider, key: keyof typeof AUTH_MIGRATIONS): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=rollbackThrough.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollbackThrough.d.ts","sourceRoot":"","sources":["../../src/test-utils/rollbackThrough.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,EAAE,MAAM,OAAO,eAAe,GAChC,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { rollbackMigration } from "@pithy-sh/core/src/migrations/runner";
|
|
4
|
+
import { MIGRATION_TABLE } from "@pithy-sh/core/src/migrations/bookkeeping";
|
|
5
|
+
//#region src/test-utils/rollbackThrough.ts
|
|
6
|
+
/**
|
|
7
|
+
* Roll the auth chain back until `key` is no longer applied, so a migration's own `down` is reached however many
|
|
8
|
+
* migrations were appended after it. Throws when `key` was never applied.
|
|
9
|
+
*/
|
|
10
|
+
async function rollbackThrough(d1, provider, key) {
|
|
11
|
+
const applied = async () => await d1.prepare(`select name from ${MIGRATION_TABLE} where name like ? limit 1`).bind(`%auth_${key}`).first() !== null;
|
|
12
|
+
if (!await applied()) throw new Error(`auth migration ${key} is not applied`);
|
|
13
|
+
while (await applied()) await rollbackMigration(d1, provider);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { rollbackThrough };
|
|
@@ -146,6 +146,31 @@ export declare const SCOPED_REGISTRY: {
|
|
|
146
146
|
readonly documentation: "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
|
+
"auth-play-integrity-service-account": {
|
|
150
|
+
readonly backend: "d1";
|
|
151
|
+
readonly scope: "environment";
|
|
152
|
+
readonly rotatable: false;
|
|
153
|
+
readonly valueType: "json";
|
|
154
|
+
readonly schema: import("zod").ZodObject<{
|
|
155
|
+
type: import("zod").ZodOptional<import("zod").ZodLiteral<"service_account">>;
|
|
156
|
+
project_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
157
|
+
private_key_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
158
|
+
private_key: import("zod").ZodString;
|
|
159
|
+
client_email: import("zod").ZodString;
|
|
160
|
+
client_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
161
|
+
token_uri: import("zod").ZodOptional<import("zod").ZodString>;
|
|
162
|
+
}, import("zod/v4/core").$strip>;
|
|
163
|
+
readonly origin: {
|
|
164
|
+
readonly kind: "obtained";
|
|
165
|
+
readonly issuer: "google";
|
|
166
|
+
readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
|
|
167
|
+
};
|
|
168
|
+
readonly rotation: {
|
|
169
|
+
readonly kind: "manual";
|
|
170
|
+
readonly issuer: "google";
|
|
171
|
+
readonly documentation: "https://console.cloud.google.com/iam-admin/serviceaccounts";
|
|
172
|
+
};
|
|
173
|
+
};
|
|
149
174
|
"email-link-signing-key": {
|
|
150
175
|
readonly backend: "cf-secrets-store";
|
|
151
176
|
readonly scope: "environment";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopedBackend.d.ts","sourceRoot":"","sources":["../../src/test-utils/scopedBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAM5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAe,MAAM,iDAAiD,CAAC;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AASlD;;;;;;;;;;GAUG;AAEH,iGAAiG;AACjG,eAAO,MAAM,qBAAqB,4CAA4C,CAAC;AAE/E,6FAA6F;AAC7F,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAEhD,+FAA+F;AAC/F,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"scopedBackend.d.ts","sourceRoot":"","sources":["../../src/test-utils/scopedBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,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AAE,UAAU,EACd,OAAO,SAAoB,GAC1B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAmC5D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
import { authDatabase } from "../data/tables.js";
|
|
4
3
|
import { authSecretsRegistry } from "../instance/secrets.js";
|
|
4
|
+
import { authDatabase } from "../data/tables.js";
|
|
5
5
|
import { NO_SOCIAL_PROVIDERS } from "../instance/providers.js";
|
|
6
6
|
import { makeAuth } from "../instance/auth.js";
|
|
7
7
|
import "../migrations/0001_init.js";
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
/** This package's npm name — the join key against a release feed. */
|
|
4
4
|
export declare const PACKAGE_NAME = "@pithy-sh/auth";
|
|
5
5
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
6
|
-
export declare const PACKAGE_VERSION = "0.
|
|
6
|
+
export declare const PACKAGE_VERSION = "0.16.0";
|
|
7
7
|
//# sourceMappingURL=version.generated.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
/** This package's npm name — the join key against a release feed. */
|
|
5
5
|
const PACKAGE_NAME = "@pithy-sh/auth";
|
|
6
6
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
7
|
-
const PACKAGE_VERSION = "0.
|
|
7
|
+
const PACKAGE_VERSION = "0.16.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PACKAGE_NAME, PACKAGE_VERSION };
|