| 1 | package web |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | |
| 6 | "amadan.net/rastrillo/rastrillo/auth" |
| 7 | ) |
| 8 | |
| 9 | // Where Base serves passkeys. The scripts are rastrillo's own: webauthn.mjs |
| 10 | // runs the browser's half of a ceremony, and the door script reveals the |
| 11 | // sign-in page's passkey button only where a ceremony can run. |
| 12 | const ( |
| 13 | webauthnModulePath = "/passkey/webauthn.mjs" |
| 14 | passkeyDoorPath = "/passkey/signin.mjs" |
| 15 | registerBeginPath = "/passkey/register/begin" |
| 16 | registerFinishPath = "/passkey/register/finish" |
| 17 | ) |
| 18 | |
| 19 | // passkeyDoor is the sign-in page's passkey button: the discover pair, which |
| 20 | // signs a member in with a passkey alone. |
| 21 | var passkeyDoor = auth.PasskeyDoor{ |
| 22 | BeginPath: "/passkey/discover/begin", |
| 23 | FinishPath: "/passkey/discover/finish", |
| 24 | ModuleURL: webauthnModulePath, |
| 25 | ScriptURL: passkeyDoorPath, |
| 26 | } |
| 27 | |
| 28 | // serveScript answers with one JavaScript module. Its URL carries no |
| 29 | // fingerprint, so the browser checks for a newer copy each time. |
| 30 | func serveScript(body []byte) http.HandlerFunc { |
| 31 | return func(w http.ResponseWriter, _ *http.Request) { |
| 32 | w.Header().Set("Content-Type", "text/javascript; charset=utf-8") |
| 33 | w.Header().Set("Cache-Control", "no-cache") |
| 34 | _, _ = w.Write(body) |
| 35 | } |
| 36 | } |
| 37 | |