@coffre/conformance 0.0.0 → 0.1.1

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/idp.d.ts ADDED
@@ -0,0 +1,146 @@
1
+ import { CryptoKey, JWK } from "jose";
2
+ //#region src/idp/people.d.ts
3
+ interface Persona {
4
+ email: string;
5
+ name: string;
6
+ /** What the seed grants them, shown on the sign-in page. */
7
+ note: string;
8
+ }
9
+ /**
10
+ * The people the sign-in pages offer. Mirrors the users in
11
+ * `dev/seed-config.mjs` (a test keeps the two in step), so each button
12
+ * lands on a seeded account.
13
+ */
14
+ export declare const PERSONAS: readonly Persona[];
15
+ interface GitHubEmail {
16
+ email: string;
17
+ primary: boolean;
18
+ verified: boolean;
19
+ visibility: 'public' | 'private' | null;
20
+ }
21
+ interface GitHubAccount {
22
+ id: number;
23
+ login: string;
24
+ name: string;
25
+ emails: GitHubEmail[];
26
+ /** Organizations the account is an active member of. */
27
+ orgs: string[];
28
+ }
29
+ interface GitHubAccountPatch {
30
+ id?: number;
31
+ login?: string;
32
+ name?: string;
33
+ /** Replaces the list. The first is primary unless one says so; all verified unless they say not. */
34
+ emails?: ReadonlyArray<{
35
+ email: string;
36
+ } & Partial<Omit<GitHubEmail, 'email'>>>;
37
+ orgs?: readonly string[];
38
+ }
39
+ //#endregion
40
+ //#region src/idp/idp.d.ts
41
+ interface DevIdpClient {
42
+ clientId: string;
43
+ clientSecret: string;
44
+ /** Matched exactly. */
45
+ redirectUris: readonly string[];
46
+ }
47
+ interface RegisteredClient extends DevIdpClient {
48
+ /** Accept any http://127.0.0.1 or http://localhost redirect URI, on any port. */
49
+ anyLoopbackRedirect: boolean;
50
+ }
51
+ interface DevIdpOptions {
52
+ /** Registered alongside the built-in `coffre-local` client. */
53
+ clients?: readonly DevIdpClient[];
54
+ /** Skip the persona page when the request carries a login hint. For tests. */
55
+ autoApprove?: boolean;
56
+ }
57
+ /** Built in, so local dev needs no registration step. */
58
+ export declare const DEFAULT_CLIENT: Readonly<{
59
+ clientId: "coffre-local";
60
+ clientSecret: "coffre-local-secret";
61
+ }>;
62
+ /**
63
+ * A local stand-in for the identity providers coffre trusts.
64
+ *
65
+ * For Cloudflare Access, it generates a keypair, serves a JWKS at the same
66
+ * `cdn-cgi` path Access uses, and mints Access-shaped tokens. It is also an
67
+ * OpenID Connect provider (under `/oauth`) signing with the same key, and an
68
+ * imitation of GitHub's OAuth apps and REST API (under `/github`). The
69
+ * point is that the code under test runs its real remote code paths against
70
+ * real HTTP endpoints -- local mode is a different implementation of the same
71
+ * interface, never a branch that skips verification.
72
+ */
73
+ export declare class DevIdp {
74
+ #private;
75
+ privateKey: CryptoKey;
76
+ publicJwk: JWK;
77
+ readonly kid = "dev-idp-key-1";
78
+ /** Used by the /dev/mint convenience endpoint when no aud is supplied. */
79
+ defaultAudience: string;
80
+ /** Fixed port for the standalone dev server; 0 (ephemeral) in tests. */
81
+ listenPort: number;
82
+ /** See {@link DevIdpOptions.autoApprove}. */
83
+ autoApprove: boolean;
84
+ constructor(options?: DevIdpOptions);
85
+ get origin(): string;
86
+ /** Matches the Cloudflare Access team-domain issuer shape. */
87
+ get issuer(): string;
88
+ /** Access publishes its keys under this exact path. */
89
+ get jwksUrl(): string;
90
+ start(): Promise<void>;
91
+ stop(): Promise<void>;
92
+ registerClient(client: DevIdpClient): void;
93
+ client(clientId: string): RegisteredClient | undefined;
94
+ /** The OIDC `sub` for an email: derived, unless {@link setSubject} overrode it. */
95
+ subjectFor(email: string): string;
96
+ /**
97
+ * From now on, whoever signs in with this email gets this subject. Simulates
98
+ * an address being recycled to a new person: same email, different account.
99
+ */
100
+ setSubject(email: string, subject: string): void;
101
+ /** The fake GitHub account that signs in with this email. */
102
+ gitHubUserFor(email: string): GitHubAccount;
103
+ /**
104
+ * From now on, whoever picks this email on the fake GitHub gets this account,
105
+ * patched over the current one. A new `id` simulates a recycled address;
106
+ * `emails` can add several, unverified ones included; `orgs` sets memberships.
107
+ */
108
+ setGitHubUser(email: string, patch: GitHubAccountPatch): void;
109
+ /** The email that signs in as a GitHub login, for GitHub's `login` hint. */
110
+ emailForGitHubLogin(login: string): string | undefined;
111
+ /** An OIDC ID token, as the token endpoint issues it. */
112
+ mintIdToken(opts: {
113
+ clientId: string;
114
+ email: string;
115
+ nonce?: string;
116
+ authTime?: number;
117
+ expiresIn?: number;
118
+ }): Promise<string>;
119
+ /** Mint a token shaped like an Access identity (human) token. */
120
+ mintUserToken(opts: {
121
+ audience: string;
122
+ email?: string;
123
+ sub?: string;
124
+ issuer?: string;
125
+ expiresIn?: number;
126
+ notBefore?: number;
127
+ key?: CryptoKey;
128
+ }): Promise<string>;
129
+ /**
130
+ * Mint a token shaped like an Access *service token*.
131
+ *
132
+ * Deliberately faithful to the real thing: no email claim at all, and an
133
+ * empty sub. Code that reads `claims.email` to identify the caller produces
134
+ * `undefined` here, which is how machine callers end up in the audit log
135
+ * with no actor.
136
+ */
137
+ mintServiceToken(opts: {
138
+ audience: string;
139
+ commonName?: string;
140
+ issuer?: string;
141
+ expiresIn?: number;
142
+ key?: CryptoKey;
143
+ }): Promise<string>;
144
+ }
145
+ //#endregion
146
+ export type { DevIdpClient, DevIdpOptions, GitHubAccount, GitHubAccountPatch, Persona, RegisteredClient };
package/dist/idp.js ADDED
@@ -0,0 +1,2 @@
1
+ import { n as DevIdp, r as PERSONAS, t as DEFAULT_CLIENT } from "./idp-DJlqS-JW.js";
2
+ export { DEFAULT_CLIENT, DevIdp, PERSONAS };