|
1 | 1 | # SDK design |
2 | 2 |
|
3 | 3 | Applications integrate with auth.piquel.fr through its Rust SDK, `piquel-auth`, its |
4 | | -TypeScript SDK, `@piquel/auth` (in development, #58), or any OpenID Connect library. The SDK follows this document and passes the shared |
5 | | -vectors in [`tests/sdk-vectors`](../../tests/sdk-vectors/README.md); an SDK in another |
6 | | -language would do the same, so every SDK accepts and rejects the same tokens and |
7 | | -challenges. |
| 4 | +TypeScript SDK, `@piquel/auth`, or any OpenID Connect library. Both SDKs follow this |
| 5 | +document and pass the shared vectors in |
| 6 | +[`tests/sdk-vectors`](../../tests/sdk-vectors/README.md); an SDK in another language |
| 7 | +would do the same, so every SDK accepts and rejects the same tokens and challenges. |
| 8 | +The Rust SDK is the reference implementation, and the TypeScript SDK mirrors its |
| 9 | +behavior and names. |
8 | 10 |
|
9 | 11 | | Path | Package | Published | Role | |
10 | 12 | | --- | --- | --- | --- | |
11 | 13 | | `crates/common` | `piquel-common` | yes | Shared types; with no features, the IDs and wire types shared by auth and the Rust SDK | |
12 | 14 | | `crates/auth-sdk` | `piquel-auth` | yes | Rust SDK; the `axum` feature adds the axum integration | |
13 | | -| `packages/auth` | `@piquel/auth` | not yet | TypeScript SDK, ESM only, with no runtime dependencies | |
| 15 | +| `packages/auth` | `@piquel/auth` | not yet | TypeScript SDK, ESM only, with no runtime dependencies: `fetch` and WebCrypto, so it runs in browsers, Node, Bun and Workers | |
14 | 16 | | `tests/sdk-vectors` | none | no | Shared test vectors | |
15 | 17 |
|
16 | 18 | ## Wire types |
@@ -54,7 +56,7 @@ older SDKs. |
54 | 56 | it understands. |
55 | 57 |
|
56 | 58 | The SDK takes an injectable clock, so tests and the vectors can pin time, and an |
57 | | -injectable HTTP client. |
| 59 | +injectable HTTP client: a `reqwest` client in Rust, a `fetch` in TypeScript. |
58 | 60 |
|
59 | 61 | ## Token validation |
60 | 62 |
|
@@ -114,17 +116,20 @@ The SDK caches the issuer's key set: |
114 | 116 | - Keys of an unknown `kty`, and keys whose `use` is not `sig`, are skipped (RFC 7517 |
115 | 117 | §5). A set where two keys share a `kid` is rejected as a whole, and the previous |
116 | 118 | set stays in use. |
| 119 | +- An RSA key whose modulus is under 2048 or over 8192 bits verifies nothing: its |
| 120 | + tokens fail with `bad_signature`. |
117 | 121 |
|
118 | 122 | This handles signing key rotation: auth publishes the new key before it signs with |
119 | | -it, so tokens from both keys verify during the overlap. The Rust key cache works |
120 | | -with any JWKS URL, so auth also uses it for Google. |
| 123 | +it, so tokens from both keys verify during the overlap. Both SDKs' key caches work |
| 124 | +with any JWKS URL, so auth also uses the Rust one for Google. |
121 | 125 |
|
122 | 126 | ## Scopes |
123 | 127 |
|
124 | 128 | Scopes are space-separated strings on the wire (RFC 6749 §3.3), and each token is |
125 | | -printable ASCII without spaces, `"` or `\`. Each SDK types them: the Rust SDK |
126 | | -declares an application's scopes once with a macro, so a required scope is a type |
127 | | -and a misspelled scope does not compile. |
| 129 | +printable ASCII without spaces, `"` or `\`. Each SDK types them, so a misspelled |
| 130 | +scope does not compile: the Rust SDK declares an application's scopes once with a |
| 131 | +macro, so a required scope is a type, and the TypeScript SDK with `defineScopes`, |
| 132 | +whose names become a union that `AccessToken.require` accepts. |
128 | 133 |
|
129 | 134 | ## Errors |
130 | 135 |
|
@@ -153,6 +158,10 @@ On a resource server, each error maps to one `WWW-Authenticate: Bearer` challeng |
153 | 158 | | `insufficient_user_authentication` | 401 | `error="insufficient_user_authentication"` with `acr_values` and `max_age` | |
154 | 159 | | A malformed `Authorization` header | 400 | `error="invalid_request"` | |
155 | 160 |
|
| 161 | +The Rust SDK's axum extractors report the request rows themselves. The TypeScript |
| 162 | +SDK's `AuthError` reports them with two codes outside the shared categories, |
| 163 | +`missing_token` and `invalid_request`, and every row with `toResponse()`. |
| 164 | + |
156 | 165 | The parameters are always written in the order `error`, `error_description`, |
157 | 166 | `scope`, `acr_values`, `max_age`, `resource_metadata`, with every value quoted, so |
158 | 167 | every SDK produces identical headers. `error_description` is printable ASCII without |
|
0 commit comments