@20baht/elysia-oauth-provider 0.0.0-stage → 0.2.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.
Files changed (62) hide show
  1. package/README.md +655 -2
  2. package/dist/config.d.ts +37 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/core/bearer.d.ts +11 -0
  5. package/dist/core/bearer.d.ts.map +1 -0
  6. package/dist/core/pkce.d.ts +6 -0
  7. package/dist/core/pkce.d.ts.map +1 -0
  8. package/dist/core/provider.d.ts +109 -0
  9. package/dist/core/provider.d.ts.map +1 -0
  10. package/dist/core/rate-limit.d.ts +61 -0
  11. package/dist/core/rate-limit.d.ts.map +1 -0
  12. package/dist/core/redirect-uri.d.ts +19 -0
  13. package/dist/core/redirect-uri.d.ts.map +1 -0
  14. package/dist/core/resource.d.ts +19 -0
  15. package/dist/core/resource.d.ts.map +1 -0
  16. package/dist/core/scope.d.ts +7 -0
  17. package/dist/core/scope.d.ts.map +1 -0
  18. package/dist/crypto/hash.d.ts +10 -0
  19. package/dist/crypto/hash.d.ts.map +1 -0
  20. package/dist/crypto/jwt.d.ts +51 -0
  21. package/dist/crypto/jwt.d.ts.map +1 -0
  22. package/dist/crypto/props-encryption.d.ts +14 -0
  23. package/dist/crypto/props-encryption.d.ts.map +1 -0
  24. package/dist/crypto/random.d.ts +8 -0
  25. package/dist/crypto/random.d.ts.map +1 -0
  26. package/dist/endpoints/authorize.d.ts +4 -0
  27. package/dist/endpoints/authorize.d.ts.map +1 -0
  28. package/dist/endpoints/http.d.ts +27 -0
  29. package/dist/endpoints/http.d.ts.map +1 -0
  30. package/dist/endpoints/metadata.d.ts +9 -0
  31. package/dist/endpoints/metadata.d.ts.map +1 -0
  32. package/dist/endpoints/register.d.ts +4 -0
  33. package/dist/endpoints/register.d.ts.map +1 -0
  34. package/dist/endpoints/revoke.d.ts +4 -0
  35. package/dist/endpoints/revoke.d.ts.map +1 -0
  36. package/dist/endpoints/token.d.ts +4 -0
  37. package/dist/endpoints/token.d.ts.map +1 -0
  38. package/dist/errors.d.ts +42 -0
  39. package/dist/errors.d.ts.map +1 -0
  40. package/dist/index.d.ts +28 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +2376 -0
  43. package/dist/index.js.map +33 -0
  44. package/dist/plugin.d.ts +426 -0
  45. package/dist/plugin.d.ts.map +1 -0
  46. package/dist/storage/conformance.d.ts +36 -0
  47. package/dist/storage/conformance.d.ts.map +1 -0
  48. package/dist/storage/conformance.js +163 -0
  49. package/dist/storage/conformance.js.map +10 -0
  50. package/dist/storage/keys.d.ts +33 -0
  51. package/dist/storage/keys.d.ts.map +1 -0
  52. package/dist/storage/memory.d.ts +35 -0
  53. package/dist/storage/memory.d.ts.map +1 -0
  54. package/dist/storage/redis.d.ts +83 -0
  55. package/dist/storage/redis.d.ts.map +1 -0
  56. package/dist/storage/redis.js +135 -0
  57. package/dist/storage/redis.js.map +10 -0
  58. package/dist/storage/types.d.ts +61 -0
  59. package/dist/storage/types.d.ts.map +1 -0
  60. package/dist/types.d.ts +329 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/package.json +67 -4
@@ -0,0 +1,37 @@
1
+ import type { EndpointPaths, OAuthProviderConfig } from './types.js';
2
+ import { type RateLimitConfig, type RateLimitRule, type RateLimitedEndpoint, type RateLimiter } from './core/rate-limit.js';
3
+ export interface ResolvedConfig<Props> extends Required<Pick<OAuthProviderConfig<Props>, 'issuer' | 'storage' | 'handleAuthorize' | 'accessTokenTTL' | 'refreshTokenTTL' | 'refreshTokenReuseGraceSeconds' | 'authCodeTTL' | 'authRequestTTL' | 'encryptProps' | 'cors' | 'hooks' | 'tokenFormat' | 'scopesSupported' | 'allowInsecureRedirectUris'>> {
4
+ issuerUrl: URL;
5
+ paths: EndpointPaths;
6
+ /** Absolute URLs for each endpoint. */
7
+ urls: EndpointPaths & {
8
+ metadata: string;
9
+ protectedResource: string;
10
+ };
11
+ resource: string | undefined;
12
+ /** Origin clients reach this server at, when it differs from the one requests arrive on. */
13
+ publicOrigin: string | undefined;
14
+ resourceMetadata: NonNullable<OAuthProviderConfig<Props>['resourceMetadata']>;
15
+ clientRegistrationTTL: number | undefined;
16
+ clientRegistration: {
17
+ enabled: boolean;
18
+ allowPublicClients: boolean;
19
+ maxBodyBytes: number;
20
+ };
21
+ rateLimit: ResolvedRateLimit | null;
22
+ accessTokenClaims: OAuthProviderConfig<Props>['accessTokenClaims'];
23
+ }
24
+ interface ResolvedRateLimit {
25
+ limiter: RateLimiter;
26
+ rules: Record<RateLimitedEndpoint, RateLimitRule | null>;
27
+ keyFor: NonNullable<RateLimitConfig['keyFor']> | null;
28
+ trustProxy: boolean | string;
29
+ }
30
+ export declare const DEFAULT_PATHS: EndpointPaths;
31
+ export declare function resolveConfig<Props>(config: OAuthProviderConfig<Props>): ResolvedConfig<Props>;
32
+ /** RFC 6749 §3.3: scope-token = 1*( %x21 / %x23-5B / %x5D-7E ) */
33
+ export declare function isValidScopeToken(s: string): boolean;
34
+ /** RFC 8707 §2: absolute URI, no fragment. We additionally require http(s). */
35
+ export declare function validateResourceUri(resource: string): URL;
36
+ export {};
37
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,cAAc,CAAC,KAAK,CAAE,SAAQ,QAAQ,CACrD,IAAI,CACF,mBAAmB,CAAC,KAAK,CAAC,EACxB,QAAQ,GACR,SAAS,GACT,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,GACjB,+BAA+B,GAC/B,aAAa,GACb,gBAAgB,GAChB,cAAc,GAC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AED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAazD"}
@@ -0,0 +1,11 @@
1
+ /** Extract the bearer token from an Authorization header (RFC 6750 §2.1). */
2
+ export declare function extractBearer(header: string | null | undefined): string | null;
3
+ export interface ChallengeOptions {
4
+ resourceMetadataUrl: string;
5
+ error?: 'invalid_token' | 'insufficient_scope' | 'invalid_request';
6
+ errorDescription?: string;
7
+ scope?: string[];
8
+ }
9
+ /** Build a `WWW-Authenticate: Bearer …` value (RFC 6750 §3, RFC 9728 §5.1). */
10
+ export declare function bearerChallenge(o: ChallengeOptions): string;
11
+ //# sourceMappingURL=bearer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearer.d.ts","sourceRoot":"","sources":["../../src/core/bearer.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAI9E;AAED,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,eAAe,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAQ3D"}
@@ -0,0 +1,6 @@
1
+ /** RFC 7636 §4.1: 43–128 chars of [A-Za-z0-9-._~] */
2
+ export declare function isValidCodeVerifier(v: string): boolean;
3
+ /** RFC 7636 §4.2: base64url(sha256) is always 43 chars. */
4
+ export declare function isValidCodeChallenge(c: string): boolean;
5
+ export declare function verifyPkce(verifier: string, challenge: string): Promise<boolean>;
6
+ //# sourceMappingURL=pkce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkce.d.ts","sourceRoot":"","sources":["../../src/core/pkce.ts"],"names":[],"mappings":"AAEA,qDAAqD;AACrD,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGtF"}
@@ -0,0 +1,109 @@
1
+ import type { ResolvedConfig } from '../config.js';
2
+ import { type JwtSigner } from '../crypto/jwt.js';
3
+ import type { AuthRequest, ClientInfo, CompleteAuthorizationOptions, GrantSummary, PendingAuthRequest, RejectAuthorizationOptions, StoredClient, TokenEndpointAuthMethod, TokenInfo, TokenResponse } from '../types.js';
4
+ export declare const AUTH_METHODS: TokenEndpointAuthMethod[];
5
+ export interface ClientCredentials {
6
+ clientId: string;
7
+ clientSecret?: string;
8
+ method: TokenEndpointAuthMethod;
9
+ }
10
+ export interface CreateClientInput {
11
+ clientId?: string;
12
+ redirectUris: string[];
13
+ clientName?: string;
14
+ clientUri?: string;
15
+ logoUri?: string;
16
+ policyUri?: string;
17
+ tosUri?: string;
18
+ jwksUri?: string;
19
+ contacts?: string[];
20
+ grantTypes?: string[];
21
+ responseTypes?: string[];
22
+ scope?: string;
23
+ tokenEndpointAuthMethod?: TokenEndpointAuthMethod;
24
+ metadata?: Record<string, unknown>;
25
+ /** Internal: mark as dynamically registered (applies registration TTL). */
26
+ dynamicallyRegistered?: boolean;
27
+ }
28
+ /**
29
+ * Framework-agnostic OAuth engine. All state goes through `config.storage`.
30
+ * The Elysia plugin is a thin HTTP layer on top of this class.
31
+ */
32
+ export declare class OAuthProviderCore<Props> {
33
+ #private;
34
+ readonly config: ResolvedConfig<Props>;
35
+ constructor(config: ResolvedConfig<Props>);
36
+ get storage(): import("../index.js").OAuthStorage;
37
+ get jwtSigner(): Promise<JwtSigner> | null;
38
+ createClient(input: CreateClientInput): Promise<ClientInfo>;
39
+ getStoredClient(clientId: string): Promise<StoredClient | null>;
40
+ lookupClient(clientId: string): Promise<ClientInfo | null>;
41
+ updateClient(clientId: string, updates: Partial<Omit<CreateClientInput, 'clientId' | 'dynamicallyRegistered'>>): Promise<ClientInfo | null>;
42
+ /** Delete a client and revoke every grant issued to it. */
43
+ deleteClient(clientId: string): Promise<void>;
44
+ listClients(): Promise<ClientInfo[]>;
45
+ /**
46
+ * Authenticate a client at the token/revocation endpoint.
47
+ * Throws `invalid_client` (401) on failure.
48
+ */
49
+ authenticateClient(creds: ClientCredentials): Promise<StoredClient>;
50
+ /**
51
+ * Validate `GET /authorize` query parameters. Errors before the client and
52
+ * redirect URI are validated have no `redirectUri` (render locally).
53
+ */
54
+ parseAuthRequest(url: URL | string): Promise<{
55
+ authRequest: AuthRequest;
56
+ client: ClientInfo;
57
+ }>;
58
+ /** Persist a validated request so the login flow only needs to carry an opaque id. */
59
+ stashAuthRequest(authRequest: AuthRequest): Promise<PendingAuthRequest>;
60
+ getAuthRequest(id: string): Promise<PendingAuthRequest | null>;
61
+ completeAuthorization(o: CompleteAuthorizationOptions<Props>): Promise<{
62
+ redirectTo: string;
63
+ }>;
64
+ /** Send the user back to the client with an error (e.g. they declined consent). */
65
+ rejectAuthorization(o: RejectAuthorizationOptions): Promise<{
66
+ redirectTo: string;
67
+ }>;
68
+ exchangeAuthorizationCode(o: {
69
+ client: StoredClient;
70
+ code: string;
71
+ codeVerifier: string | undefined;
72
+ redirectUri: string | undefined;
73
+ resource: string | undefined;
74
+ requestedScope: string | undefined;
75
+ }): Promise<TokenResponse>;
76
+ refreshAccessToken(o: {
77
+ client: StoredClient;
78
+ refreshToken: string;
79
+ requestedScope: string | undefined;
80
+ resource: string | undefined;
81
+ }): Promise<TokenResponse>;
82
+ /**
83
+ * Verify a bearer token. Returns `null` when invalid/expired/revoked.
84
+ * Throws `OAuthError('invalid_token')` when the token is valid but its
85
+ * audience does not cover `requestUrl`.
86
+ */
87
+ verifyAccessToken(token: string, requestUrl?: string): Promise<TokenInfo<Props> | null>;
88
+ /**
89
+ * RFC 7009 revocation. Never reveals whether the token existed. Only tokens
90
+ * owned by `client` are affected.
91
+ */
92
+ revokeToken(o: {
93
+ client: StoredClient;
94
+ token: string;
95
+ tokenTypeHint?: string;
96
+ }): Promise<void>;
97
+ /**
98
+ * Delete a grant, all its access tokens and refresh pointers. The grant
99
+ * record is removed by compare-and-delete: a refresh or code exchange that
100
+ * commits in between bumps the version, so the loop re-reads and also
101
+ * removes what that commit minted.
102
+ */
103
+ revokeGrant(grantId: string, userId: string): Promise<void>;
104
+ listUserGrants(userId: string): Promise<GrantSummary[]>;
105
+ /** Every live grant, across all users and clients. */
106
+ listGrants(): Promise<GrantSummary[]>;
107
+ listClientGrants(clientId: string): Promise<GrantSummary[]>;
108
+ }
109
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/core/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAmD,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAYnG,OAAO,KAAK,EAEV,WAAW,EAEX,UAAU,EACV,4BAA4B,EAE5B,YAAY,EACZ,kBAAkB,EAElB,0BAA0B,EAC1B,YAAY,EACZ,uBAAuB,EACvB,SAAS,EACT,aAAa,EACd,MAAM,aAAa,CAAC;AAgBrB,eAAO,MAAM,YAAY,EAAE,uBAAuB,EAIjD,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,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CAAC;KAC9B,GAAG,OAAO,CAAC,aAAa,CAAC;IAuU1B;;;;OAIG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IA4B7F;;;OAGG;IACG,WAAW,CAAC,CAAC,EAAE;QACnB,MAAM,EAAE,YAAY,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBjB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB3D,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAI7D,sDAAsD;IAChD,UAAU,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAIrC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CA0ClE"}
@@ -0,0 +1,61 @@
1
+ export interface RateLimitRule {
2
+ /** Requests allowed per window. */
3
+ max: number;
4
+ windowSeconds: number;
5
+ }
6
+ export interface RateLimitDecision {
7
+ allowed: boolean;
8
+ /** Seconds until the window resets (sent as `Retry-After` when blocked). */
9
+ retryAfterSeconds: number;
10
+ remaining: number;
11
+ }
12
+ /**
13
+ * Pluggable counter. `hit` records one request for `key` and says whether it
14
+ * is still within `rule`. Implementations: `MemoryRateLimiter` (single
15
+ * process) and `RedisRateLimiter` (shared, in `storage/redis`).
16
+ */
17
+ export interface RateLimiter {
18
+ hit(key: string, rule: RateLimitRule): Promise<RateLimitDecision>;
19
+ }
20
+ export type RateLimitedEndpoint = 'token' | 'register' | 'authorize' | 'revoke';
21
+ export interface RateLimitConfig {
22
+ /** Counter backend. Default `new MemoryRateLimiter()`. */
23
+ limiter?: RateLimiter;
24
+ /** `false` disables limiting for that endpoint. */
25
+ token?: RateLimitRule | false;
26
+ register?: RateLimitRule | false;
27
+ authorize?: RateLimitRule | false;
28
+ revoke?: RateLimitRule | false;
29
+ /**
30
+ * Derive the bucket key. Return `null` to skip limiting for this request.
31
+ * Default: `${endpoint}:${ip}` where `ip` is the socket address, or the
32
+ * first `X-Forwarded-For` entry when `trustProxy` is `true`, or the verbatim
33
+ * value of the named header when `trustProxy` is a string.
34
+ */
35
+ keyFor?: (input: {
36
+ endpoint: RateLimitedEndpoint;
37
+ request: Request;
38
+ ip: string | null;
39
+ }) => string | null | Promise<string | null>;
40
+ /**
41
+ * Read the client IP from a proxy header. `true` uses the first
42
+ * `X-Forwarded-For` entry; a string names the header to read verbatim
43
+ * (e.g. `'cf-connecting-ip'`). Only enable behind a proxy you control.
44
+ */
45
+ trustProxy?: boolean | string;
46
+ }
47
+ export declare const DEFAULT_RATE_LIMITS: Record<RateLimitedEndpoint, RateLimitRule>;
48
+ /**
49
+ * Fixed-window counter in a `Map`. Per process only — use `RedisRateLimiter`
50
+ * (or your own) when running more than one instance.
51
+ */
52
+ export declare class MemoryRateLimiter implements RateLimiter {
53
+ #private;
54
+ constructor(options?: {
55
+ now?: () => number;
56
+ });
57
+ hit(key: string, rule: RateLimitRule): Promise<RateLimitDecision>;
58
+ sweep(): void;
59
+ }
60
+ export declare function clientIpFrom(request: Request, socketIp: string | null, trustProxy: boolean | string): string | null;
61
+ //# sourceMappingURL=rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/core/rate-limit.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,C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AChB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,UAAU,EAAE,OAAO,GAAG,MAAM,GAC3B,MAAM,GAAG,IAAI,CAUf"}
@@ -0,0 +1,19 @@
1
+ export interface RedirectUriPolicy {
2
+ /** Skip the OAuth 2.1 / RFC 8252 scheme and host policy; only `DANGEROUS_SCHEMES` stay rejected. */
3
+ allowInsecure: boolean;
4
+ }
5
+ /**
6
+ * Syntactic check for redirect URIs at registration and authorization time.
7
+ * Returns an error message or `null` when acceptable.
8
+ *
9
+ * Default policy (OAuth 2.1 §1.5, RFC 8252 §7): `https:`; `http:` only to a
10
+ * loopback host; private-use schemes in reverse-DNS form (`com.example.app:/cb`).
11
+ */
12
+ export declare function validateRedirectUriSyntax(uri: string, policy?: RedirectUriPolicy): string | null;
13
+ /**
14
+ * Exact string match (OAuth 2.1 §4.1.3), except for loopback redirect URIs
15
+ * (RFC 8252 §7.3) where the port may vary.
16
+ */
17
+ export declare function redirectUriMatches(registered: string, requested: string): boolean;
18
+ export declare function isRegisteredRedirectUri(redirectUris: readonly string[], requested: string): boolean;
19
+ //# sourceMappingURL=redirect-uri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect-uri.d.ts","sourceRoot":"","sources":["../../src/core/redirect-uri.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,iBAAiB;IAChC,oGAAoG;IACpG,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,iBAA4C,GACnD,MAAM,GAAG,IAAI,CAuBf;AAYD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAmBjF;AAED,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,SAAS,EAAE,MAAM,GAChB,OAAO,CAET"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * RFC 8707 resource handling.
3
+ *
4
+ * - When the provider is configured with a canonical `resource`, every
5
+ * grant/token is bound to it; requests naming a different resource are
6
+ * rejected with `invalid_target`.
7
+ * - Otherwise a token is bound to the resource the grant carries (from the
8
+ * client's request or `completeAuthorization({ resource })`), if any, and
9
+ * protected routes check that the request URL falls under it.
10
+ */
11
+ export declare function normalizeResource(resource: string): string;
12
+ export declare function resourcesEqual(a: string, b: string): boolean;
13
+ /**
14
+ * True when `requestUrl` is covered by the token's `audience`:
15
+ * same origin, same query (if the audience has one), and the audience path is
16
+ * a path-boundary prefix of the request path.
17
+ */
18
+ export declare function audienceCoversUrl(audience: string, requestUrl: string): boolean;
19
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/core/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAM5D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAc/E"}
@@ -0,0 +1,7 @@
1
+ /** Parse a space-delimited scope string, deduplicating and validating tokens. Returns null if any token is invalid. */
2
+ export declare function parseScope(scope: string | undefined | null): string[] | null;
3
+ export declare const formatScope: (scopes: readonly string[]) => string;
4
+ export declare function isSubset(subset: readonly string[], superset: readonly string[]): boolean;
5
+ /** Requested ∩ granted, or `granted` when nothing requested. Returns null when requested ⊄ granted. */
6
+ export declare function downscope(requested: readonly string[] | undefined, granted: readonly string[]): string[] | null;
7
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/core/scope.ts"],"names":[],"mappings":"AAEA,uHAAuH;AACvH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,IAAI,CAS5E;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,SAAS,MAAM,EAAE,KAAG,MAA0B,CAAC;AAEnF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAExF;AAED,uGAAuG;AACvG,wBAAgB,SAAS,CACvB,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACxC,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,EAAE,GAAG,IAAI,CAIjB"}
@@ -0,0 +1,10 @@
1
+ export declare function sha256Hex(input: string): Promise<string>;
2
+ export declare function sha256Base64Url(input: string): Promise<string>;
3
+ export declare function bytesToBase64Url(bytes: Uint8Array): string;
4
+ export declare function base64UrlToBytes(str: string): Uint8Array<ArrayBuffer>;
5
+ /**
6
+ * Constant-time string equality. Compares UTF-8 bytes; strings of different
7
+ * length still run a full comparison against `a` before returning false.
8
+ */
9
+ export declare function timingSafeEqual(a: string, b: string): boolean;
10
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/crypto/hash.ts"],"names":[],"mappings":"AAEA,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9D;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGpE;AAQD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI1D;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CASrE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAM7D"}
@@ -0,0 +1,51 @@
1
+ import { type JWK, type JWTPayload, type CryptoKey as JoseCryptoKey, type KeyObject } from 'jose';
2
+ /**
3
+ * Claims the provider sets on every access token. `sub` and `grant_id` locate
4
+ * the stored token record, so `accessTokenClaims` may not replace any of them.
5
+ */
6
+ export declare const ACCESS_TOKEN_REGISTERED_CLAIMS: readonly ["iss", "sub", "aud", "exp", "iat", "jti", "client_id", "scope", "grant_id"];
7
+ type KeyInput = JoseCryptoKey | KeyObject | Uint8Array | JWK | string;
8
+ export type JwtTokenFormat = {
9
+ type: 'jwt';
10
+ alg: 'ES256' | 'RS256' | 'EdDSA';
11
+ /** PKCS#8 PEM string, JWK, or CryptoKey. */
12
+ privateKey: KeyInput;
13
+ /** SPKI PEM string, JWK, or CryptoKey. Derived from the JWK/CryptoKey when omitted. */
14
+ publicKey?: KeyInput;
15
+ /** Required when `additionalPublicKeys` is used. */
16
+ kid?: string;
17
+ /**
18
+ * Keys that were rotated out but whose tokens must keep verifying. Tokens
19
+ * are matched by their `kid` header against the primary key and these;
20
+ * all are published in the JWKS. Signing always uses the primary key.
21
+ */
22
+ additionalPublicKeys?: {
23
+ publicKey: KeyInput;
24
+ kid: string;
25
+ }[];
26
+ } | {
27
+ type: 'jwt';
28
+ alg: 'HS256';
29
+ /** Raw secret (string is UTF-8 encoded). Minimum 32 bytes. */
30
+ secret: string | Uint8Array;
31
+ kid?: string;
32
+ };
33
+ export interface JwtSigner {
34
+ readonly alg: string;
35
+ readonly kid: string | undefined;
36
+ sign(payload: JWTPayload, opts: {
37
+ expiresAt: number;
38
+ issuedAt: number;
39
+ jti: string;
40
+ }): Promise<string>;
41
+ verify(token: string, expected: {
42
+ issuer: string;
43
+ }): Promise<JWTPayload | null>;
44
+ /** Public JWKS document, or `null` for symmetric algorithms. */
45
+ jwks(): Promise<{
46
+ keys: JWK[];
47
+ } | null>;
48
+ }
49
+ export declare function createJwtSigner(format: JwtTokenFormat): Promise<JwtSigner>;
50
+ export {};
51
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/crypto/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,GAAG,EACR,KAAK,UAAU,EACf,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAEd;;;GAGG;AACH,eAAO,MAAM,8BAA8B,uFAUjC,CAAC;AAEX,KAAK,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,GAAG,GAAG,MAAM,CAAC;AAEtE,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IACjC,4CAA4C;IAC5C,UAAU,EAAE,QAAQ,CAAC;IACrB,uFAAuF;IACvF,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,oBAAoB,CAAC,EAAE;QAAE,SAAS,EAAE,QAAQ,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC/D,GACD;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;IACb,8DAA8D;IAC9D,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CACF,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GACzD,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAChF,gEAAgE;IAChE,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACzC;AA6BD,wBAAsB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CA8DhF"}
@@ -0,0 +1,14 @@
1
+ export interface EncryptedProps {
2
+ /** base64url ciphertext (AES-GCM, includes tag). */
3
+ ciphertext: string;
4
+ key: CryptoKey;
5
+ }
6
+ export declare function encryptProps(props: unknown): Promise<EncryptedProps>;
7
+ export declare function decryptProps<T>(ciphertext: string, key: CryptoKey): Promise<T>;
8
+ /** Wrap `key` so that only the holder of `credential` can unwrap it. */
9
+ export declare function wrapKeyWithCredential(key: CryptoKey, credential: string): Promise<string>;
10
+ export declare function unwrapKeyWithCredential(wrapped: string, credential: string): Promise<CryptoKey>;
11
+ /** Encrypt `plaintext` so that only the holder of `credential` can read it back. */
12
+ export declare function sealWithCredential(credential: string, plaintext: string): Promise<string>;
13
+ export declare function openWithCredential(credential: string, sealed: string): Promise<string>;
14
+ //# sourceMappingURL=props-encryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props-encryption.d.ts","sourceRoot":"","sources":["../../src/crypto/props-encryption.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,SAAS,CAAC;CAChB;AAED,wBAAsB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAQ1E;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAOpF;AAcD,wEAAwE;AACxE,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/F;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,CAAC,CAWpB;AAkBD,oFAAoF;AACpF,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU/F;AAED,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5F"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * URL-safe random string. Alphabet has exactly 64 symbols so `byte % 64`
3
+ * introduces no modulo bias.
4
+ */
5
+ export declare function randomString(length: number): string;
6
+ export declare const randomId: () => string;
7
+ export declare const randomSecret: () => string;
8
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/crypto/random.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,eAAO,MAAM,QAAQ,QAAO,MAA0B,CAAC;AACvD,eAAO,MAAM,YAAY,QAAO,MAA0B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { OAuthProviderCore } from '../core/provider.js';
2
+ /** `GET /authorize`: validate, stash, delegate to the app's login UI. */
3
+ export declare function handleAuthorize<Props>(core: OAuthProviderCore<Props>, request: Request): Promise<Response>;
4
+ //# sourceMappingURL=authorize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../src/endpoints/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG7D,yEAAyE;AACzE,wBAAsB,eAAe,CAAC,KAAK,EACzC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAqBnB"}
@@ -0,0 +1,27 @@
1
+ import type { ClientCredentials } from '../core/provider.js';
2
+ export declare const NO_STORE: Record<string, string>;
3
+ export declare function corsHeaders(request: Request): Record<string, string>;
4
+ export declare function json(body: unknown, init?: {
5
+ status?: number;
6
+ headers?: Record<string, string>;
7
+ }): Response;
8
+ export declare function methodNotAllowed(allow: string): Response;
9
+ /**
10
+ * Read the body as UTF-8 text, stopping once more than `maxBytes` bytes have
11
+ * arrived (413) so an oversized or chunked body is never fully buffered.
12
+ */
13
+ export declare function readBodyText(request: Request, maxBytes: number): Promise<string>;
14
+ export interface ParsedForm {
15
+ /** Single-valued params (any repeated one already rejected). */
16
+ get(name: string): string | undefined;
17
+ /** `resource` may legally repeat. */
18
+ getAll(name: string): string[];
19
+ }
20
+ /** Strict `application/x-www-form-urlencoded` parsing (RFC 6749 §4.1.3, §3.2). */
21
+ export declare function parseFormBody(request: Request, repeatable?: readonly string[]): Promise<ParsedForm>;
22
+ /**
23
+ * Extract client credentials from Basic auth or the form body (RFC 6749 §2.3.1).
24
+ * Mixing both is rejected.
25
+ */
26
+ export declare function extractClientCredentials(request: Request, form: ParsedForm): ClientCredentials;
27
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/endpoints/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAuD,CAAC;AAEpG,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWpE;AAED,wBAAgB,IAAI,CAClB,IAAI,EAAE,OAAO,EACb,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GAC/D,QAAQ,CAEV;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAKxD;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBtF;AAED,MAAM,WAAW,UAAU;IACzB,gEAAgE;IAChE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,qCAAqC;IACrC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAChC;AAED,kFAAkF;AAClF,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,GAAE,SAAS,MAAM,EAAiB,GAC3C,OAAO,CAAC,UAAU,CAAC,CA0BrB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,iBAAiB,CAuC9F"}
@@ -0,0 +1,9 @@
1
+ import type { OAuthProviderCore } from '../core/provider.js';
2
+ /** RFC 8414 Authorization Server Metadata. */
3
+ export declare function authorizationServerMetadata<Props>(core: OAuthProviderCore<Props>): Record<string, unknown>;
4
+ /**
5
+ * RFC 9728 Protected Resource Metadata.
6
+ * `suffix` is whatever followed `/.well-known/oauth-protected-resource` in the request path.
7
+ */
8
+ export declare function protectedResourceMetadata<Props>(core: OAuthProviderCore<Props>, suffix: string): Record<string, unknown>;
9
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/endpoints/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,8CAA8C;AAC9C,wBAAgB,2BAA2B,CAAC,KAAK,EAC/C,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BzB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAC7C,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBzB"}
@@ -0,0 +1,4 @@
1
+ import { type OAuthProviderCore } from '../core/provider.js';
2
+ /** RFC 7591 Dynamic Client Registration. */
3
+ export declare function handleRegister<Props>(core: OAuthProviderCore<Props>, request: Request): Promise<Response>;
4
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/endpoints/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKnG,4CAA4C;AAE5C,wBAAsB,cAAc,CAAC,KAAK,EACxC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAsGnB"}
@@ -0,0 +1,4 @@
1
+ import type { OAuthProviderCore } from '../core/provider.js';
2
+ /** `POST /revoke` (RFC 7009). Always 200 for well-formed authenticated requests. */
3
+ export declare function handleRevoke<Props>(core: OAuthProviderCore<Props>, request: Request): Promise<Response>;
4
+ //# sourceMappingURL=revoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../src/endpoints/revoke.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI7D,oFAAoF;AACpF,wBAAsB,YAAY,CAAC,KAAK,EACtC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAYnB"}
@@ -0,0 +1,4 @@
1
+ import type { OAuthProviderCore } from '../core/provider.js';
2
+ /** `POST /token` — authorization_code and refresh_token grants. */
3
+ export declare function handleToken<Props>(core: OAuthProviderCore<Props>, request: Request): Promise<Response>;
4
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/endpoints/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI7D,mEAAmE;AACnE,wBAAsB,WAAW,CAAC,KAAK,EACrC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAC9B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAyCnB"}
@@ -0,0 +1,42 @@
1
+ /** RFC 6749 / 7591 / 7009 / 8707 error codes plus a few used by the token endpoint. */
2
+ export type OAuthErrorCode = 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'unsupported_response_type' | 'invalid_scope' | 'invalid_target' | 'access_denied' | 'server_error' | 'temporarily_unavailable' | 'invalid_client_metadata' | 'invalid_redirect_uri' | 'invalid_token' | 'insufficient_scope' | 'unsupported_token_type';
3
+ /**
4
+ * Error returned as a JSON body `{ error, error_description }` with the given
5
+ * HTTP status. Thrown inside endpoint handlers; never leaks internals.
6
+ */
7
+ export declare class OAuthError extends Error {
8
+ readonly code: OAuthErrorCode;
9
+ readonly status: number;
10
+ readonly headers: Record<string, string>;
11
+ constructor(code: OAuthErrorCode, description: string, options?: {
12
+ status?: number;
13
+ headers?: Record<string, string>;
14
+ cause?: unknown;
15
+ });
16
+ toJSON(): {
17
+ error: OAuthErrorCode;
18
+ error_description: string;
19
+ };
20
+ toResponse(extraHeaders?: Record<string, string>): Response;
21
+ }
22
+ /**
23
+ * Error raised while validating an authorization request.
24
+ * When `redirectUri` is set the client and redirect URI were already validated
25
+ * and the error MUST be delivered by redirecting the user-agent (RFC 6749 §4.1.2.1).
26
+ * Otherwise it must be rendered locally — never redirect to an unvalidated URI.
27
+ */
28
+ export declare class AuthorizationError extends Error {
29
+ readonly code: OAuthErrorCode;
30
+ readonly redirectUri: string | undefined;
31
+ readonly state: string | undefined;
32
+ readonly issuer: string | undefined;
33
+ constructor(code: OAuthErrorCode, description: string, options?: {
34
+ redirectUri?: string;
35
+ state?: string;
36
+ issuer?: string;
37
+ });
38
+ /** Redirect URL carrying the error, or `null` when it must be rendered locally. */
39
+ toRedirectUrl(): string | null;
40
+ toResponse(): Response;
41
+ }
42
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,qBAAqB,GACrB,wBAAwB,GACxB,2BAA2B,GAC3B,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,cAAc,GACd,yBAAyB,GACzB,yBAAyB,GACzB,sBAAsB,GACtB,eAAe,GACf,oBAAoB,GACpB,wBAAwB,CAAC;AAE7B;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAGvC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;IAStF,MAAM,IAAI;QAAE,KAAK,EAAE,cAAc,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE;IAI9D,UAAU,CAAC,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,QAAQ;CAWhE;AAkBD;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAGlC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAUzE,mFAAmF;IACnF,aAAa,IAAI,MAAM,GAAG,IAAI;IAU9B,UAAU,IAAI,QAAQ;CAavB"}
@@ -0,0 +1,28 @@
1
+ export { oauthProvider } from './plugin.js';
2
+ export type { OAuthHelpers, OAuthMacroOptions, OAuthProviderPlugin } from './plugin.js';
3
+ export { OAuthProviderCore } from './core/provider.js';
4
+ export type { CreateClientInput, ClientCredentials } from './core/provider.js';
5
+ export { resolveConfig, isValidScopeToken, validateResourceUri } from './config.js';
6
+ export type { ResolvedConfig } from './config.js';
7
+ export { OAuthError, AuthorizationError } from './errors.js';
8
+ export type { OAuthErrorCode } from './errors.js';
9
+ export { MemoryStorage } from './storage/memory.js';
10
+ export type { MemoryStorageOptions } from './storage/memory.js';
11
+ export { assertStorageContract } from './storage/types.js';
12
+ export type { OAuthStorage, StorageSetOptions, Versioned } from './storage/types.js';
13
+ export { keys as storageKeys, KEY_PREFIX } from './storage/keys.js';
14
+ export { extractBearer, bearerChallenge } from './core/bearer.js';
15
+ export { normalizeResource, resourcesEqual, audienceCoversUrl } from './core/resource.js';
16
+ export { redirectUriMatches, validateRedirectUriSyntax } from './core/redirect-uri.js';
17
+ export { createJwtSigner, ACCESS_TOKEN_REGISTERED_CLAIMS } from './crypto/jwt.js';
18
+ export type { JwtSigner } from './crypto/jwt.js';
19
+ export type * from './types.js';
20
+ export { RedisStorage, escapeGlob, REDIS_SCRIPTS } from './storage/redis.js';
21
+ export type { RedisLikeClient, RedisStorageOptions } from './storage/redis.js';
22
+ export { DEFAULT_PATHS } from './config.js';
23
+ export { isValidCodeVerifier, isValidCodeChallenge, verifyPkce } from './core/pkce.js';
24
+ export { RedisRateLimiter } from './storage/redis.js';
25
+ export type { RedisRateLimitClient } from './storage/redis.js';
26
+ export { MemoryRateLimiter, DEFAULT_RATE_LIMITS, clientIpFrom } from './core/rate-limit.js';
27
+ export type { RateLimiter, RateLimitRule, RateLimitDecision, RateLimitConfig, RateLimitedEndpoint, } from './core/rate-limit.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACpF,YAAY,EAAE,cAAc,EAAE,MAA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