Review an OAuth PKCE callback

src/oauth-types.tsTypeScript
@@ -0,0 +1,46 @@
1+export interface OAuthAttempt {
2+ state: string;
3+ verifier: string;
4+ redirectUri: string;
5+ returnTo: string;
6+ createdAtMilliseconds: number;
7+}
8+
9+export interface OAuthAttemptStore {
10+ put(attempt: OAuthAttempt): Promise<void>;
11+ get(state: string): Promise<OAuthAttempt | null>;
12+ delete(state: string): Promise<void>;
13+ takeActive(
14+ state: string,
15+ nowMilliseconds: number,
16+ maxAgeMilliseconds: number,
17+ ): Promise<OAuthAttempt | null>;
18+}
19+
20+export interface OAuthProvider {
21+ authorizationUrl(input: {
22+ state: string;
23+ challenge: string;
24+ redirectUri: string;
25+ }): string;
26+ exchange(input: {
27+ code: string;
28+ verifier: string;
29+ redirectUri: string;
30+ }): Promise<{ subject: string }>;
31+}
32+
33+export interface SessionStore {
34+ bindExisting(sessionId: string | undefined, subject: string): Promise<string>;
35+ createRotated(previousSessionId: string | undefined, subject: string): Promise<string>;
36+}
37+
38+export interface OAuthDependencies {
39+ attempts: OAuthAttemptStore;
40+ provider: OAuthProvider;
41+ sessions: SessionStore;
42+ clock: { nowMilliseconds(): number };
43+ ids: { next(): string };
44+ stateSecrets: { nextState(): string };
45+ secrets: { nextVerifier(): { verifier: string; challenge: string } };
46+}