@hamur/auth 0.0.0-stage → 0.0.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.
Files changed (240) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +14 -2
  3. package/dist/chunks/bun-index-0grce57w.js +47 -0
  4. package/dist/chunks/bun-index-nn9z2k40.js +92 -0
  5. package/dist/chunks/bun-index-pmpez2a8.js +10 -0
  6. package/dist/chunks/bun-index-r6757s88.js +206 -0
  7. package/dist/src/adapters/angular.js +63 -0
  8. package/dist/src/adapters/html.js +29 -0
  9. package/dist/src/adapters/preact.js +37 -0
  10. package/dist/src/adapters/react.js +32 -0
  11. package/dist/src/adapters/solid.js +45 -0
  12. package/dist/src/adapters/svelte.js +44 -0
  13. package/dist/src/adapters/vue.js +55 -0
  14. package/dist/src/index.js +688 -0
  15. package/dist/src/middleware.js +45 -0
  16. package/dist/src/route-middleware.js +42 -0
  17. package/dist/src/server/index.js +2971 -0
  18. package/dist/types/src/adapters/angular.d.ts +32 -0
  19. package/dist/types/src/adapters/html.d.ts +15 -0
  20. package/dist/types/src/adapters/preact.d.ts +19 -0
  21. package/dist/types/src/adapters/react.d.ts +19 -0
  22. package/dist/types/src/adapters/solid.d.ts +25 -0
  23. package/dist/types/src/adapters/svelte-session.d.ts +8 -0
  24. package/dist/types/src/adapters/svelte-webauthn.d.ts +8 -0
  25. package/dist/types/src/adapters/svelte.d.ts +5 -0
  26. package/dist/types/src/adapters/vue.d.ts +25 -0
  27. package/dist/types/src/build/access-tokens.d.ts +4 -0
  28. package/dist/types/src/build/client.d.ts +4 -0
  29. package/dist/types/src/build/dev-key.d.ts +6 -0
  30. package/dist/types/src/build/email.d.ts +4 -0
  31. package/dist/types/src/build/guards.d.ts +4 -0
  32. package/dist/types/src/build/module-entry.d.ts +3 -0
  33. package/dist/types/src/build/oauth.d.ts +8 -0
  34. package/dist/types/src/build/session.d.ts +6 -0
  35. package/dist/types/src/build/single-use.d.ts +15 -0
  36. package/dist/types/src/build/webauthn.d.ts +7 -0
  37. package/dist/types/src/client/webauthn.d.ts +37 -0
  38. package/dist/types/src/index.d.ts +43 -0
  39. package/dist/types/src/middleware.d.ts +4 -0
  40. package/dist/types/src/module.d.ts +3 -0
  41. package/dist/types/src/options.d.ts +4 -0
  42. package/dist/types/src/route-middleware.d.ts +2 -0
  43. package/dist/types/src/runtime/middleware/auth.d.ts +3 -0
  44. package/dist/types/src/runtime/middleware/guest.d.ts +3 -0
  45. package/dist/types/src/runtime/payload.d.ts +2 -0
  46. package/dist/types/src/runtime/plugin.d.ts +2 -0
  47. package/dist/types/src/runtime/store.d.ts +28 -0
  48. package/dist/types/src/runtime/targets.d.ts +4 -0
  49. package/dist/types/src/server/access-token.d.ts +27 -0
  50. package/dist/types/src/server/auth-link.d.ts +15 -0
  51. package/dist/types/src/server/door.d.ts +4 -0
  52. package/dist/types/src/server/endpoint.d.ts +8 -0
  53. package/dist/types/src/server/guard.d.ts +12 -0
  54. package/dist/types/src/server/hooks.d.ts +5 -0
  55. package/dist/types/src/server/index.d.ts +88 -0
  56. package/dist/types/src/server/oauth/atproto-dns.d.ts +1 -0
  57. package/dist/types/src/server/oauth/atproto-fetch.d.ts +13 -0
  58. package/dist/types/src/server/oauth/atproto-metadata.d.ts +1 -0
  59. package/dist/types/src/server/oauth/atproto.d.ts +36 -0
  60. package/dist/types/src/server/oauth/cookie.d.ts +17 -0
  61. package/dist/types/src/server/oauth/dpop.d.ts +4 -0
  62. package/dist/types/src/server/oauth/handler.d.ts +101 -0
  63. package/dist/types/src/server/oauth/oidc.d.ts +20 -0
  64. package/dist/types/src/server/oauth/providers/apple.d.ts +26 -0
  65. package/dist/types/src/server/oauth/providers/atlassian.d.ts +5 -0
  66. package/dist/types/src/server/oauth/providers/auth0.d.ts +9 -0
  67. package/dist/types/src/server/oauth/providers/authentik.d.ts +9 -0
  68. package/dist/types/src/server/oauth/providers/azureb2c.d.ts +11 -0
  69. package/dist/types/src/server/oauth/providers/battledotnet.d.ts +5 -0
  70. package/dist/types/src/server/oauth/providers/box.d.ts +5 -0
  71. package/dist/types/src/server/oauth/providers/catalog.d.ts +12 -0
  72. package/dist/types/src/server/oauth/providers/cloudflare.d.ts +11 -0
  73. package/dist/types/src/server/oauth/providers/cognito.d.ts +9 -0
  74. package/dist/types/src/server/oauth/providers/discord.d.ts +5 -0
  75. package/dist/types/src/server/oauth/providers/dropbox.d.ts +5 -0
  76. package/dist/types/src/server/oauth/providers/facebook.d.ts +5 -0
  77. package/dist/types/src/server/oauth/providers/gitea.d.ts +9 -0
  78. package/dist/types/src/server/oauth/providers/github.d.ts +5 -0
  79. package/dist/types/src/server/oauth/providers/gitlab.d.ts +9 -0
  80. package/dist/types/src/server/oauth/providers/google.d.ts +5 -0
  81. package/dist/types/src/server/oauth/providers/heroku.d.ts +5 -0
  82. package/dist/types/src/server/oauth/providers/hubspot.d.ts +5 -0
  83. package/dist/types/src/server/oauth/providers/instagram.d.ts +5 -0
  84. package/dist/types/src/server/oauth/providers/keycloak.d.ts +11 -0
  85. package/dist/types/src/server/oauth/providers/kick.d.ts +5 -0
  86. package/dist/types/src/server/oauth/providers/line.d.ts +5 -0
  87. package/dist/types/src/server/oauth/providers/linear.d.ts +5 -0
  88. package/dist/types/src/server/oauth/providers/linkedin.d.ts +5 -0
  89. package/dist/types/src/server/oauth/providers/livechat.d.ts +5 -0
  90. package/dist/types/src/server/oauth/providers/mastodon.d.ts +9 -0
  91. package/dist/types/src/server/oauth/providers/microsoft.d.ts +9 -0
  92. package/dist/types/src/server/oauth/providers/okta.d.ts +9 -0
  93. package/dist/types/src/server/oauth/providers/ory.d.ts +9 -0
  94. package/dist/types/src/server/oauth/providers/osu.d.ts +5 -0
  95. package/dist/types/src/server/oauth/providers/paypal.d.ts +5 -0
  96. package/dist/types/src/server/oauth/providers/polar.d.ts +5 -0
  97. package/dist/types/src/server/oauth/providers/preset.d.ts +74 -0
  98. package/dist/types/src/server/oauth/providers/riotgames.d.ts +5 -0
  99. package/dist/types/src/server/oauth/providers/roblox.d.ts +5 -0
  100. package/dist/types/src/server/oauth/providers/salesforce.d.ts +9 -0
  101. package/dist/types/src/server/oauth/providers/seznam.d.ts +5 -0
  102. package/dist/types/src/server/oauth/providers/shopifyCustomer.d.ts +9 -0
  103. package/dist/types/src/server/oauth/providers/slack.d.ts +5 -0
  104. package/dist/types/src/server/oauth/providers/spotify.d.ts +5 -0
  105. package/dist/types/src/server/oauth/providers/steam.d.ts +23 -0
  106. package/dist/types/src/server/oauth/providers/strava.d.ts +5 -0
  107. package/dist/types/src/server/oauth/providers/tiktok.d.ts +5 -0
  108. package/dist/types/src/server/oauth/providers/twitch.d.ts +5 -0
  109. package/dist/types/src/server/oauth/providers/vk.d.ts +5 -0
  110. package/dist/types/src/server/oauth/providers/wechat.d.ts +5 -0
  111. package/dist/types/src/server/oauth/providers/workos.d.ts +5 -0
  112. package/dist/types/src/server/oauth/providers/x.d.ts +5 -0
  113. package/dist/types/src/server/oauth/providers/xsuaa.d.ts +9 -0
  114. package/dist/types/src/server/oauth/providers/yandex.d.ts +5 -0
  115. package/dist/types/src/server/oauth/providers/zendesk.d.ts +9 -0
  116. package/dist/types/src/server/oauth/providers/zitadel.d.ts +9 -0
  117. package/dist/types/src/server/personal.d.ts +5 -0
  118. package/dist/types/src/server/session.d.ts +20 -0
  119. package/dist/types/src/server/token-requests.d.ts +5 -0
  120. package/dist/types/src/server/token.d.ts +17 -0
  121. package/dist/types/src/server/totp.d.ts +28 -0
  122. package/dist/types/src/server/webauthn/cbor.d.ts +16 -0
  123. package/dist/types/src/server/webauthn/cose.d.ts +17 -0
  124. package/dist/types/src/server/webauthn/data.d.ts +20 -0
  125. package/dist/types/src/server/webauthn/handler.d.ts +63 -0
  126. package/dist/types/src/single-use.d.ts +17 -0
  127. package/dist/types/src/types.d.ts +88 -0
  128. package/package.json +122 -4
  129. package/src/adapters/AuthState.svelte +14 -0
  130. package/src/adapters/angular.ts +80 -0
  131. package/src/adapters/html.ts +39 -0
  132. package/src/adapters/preact.ts +53 -0
  133. package/src/adapters/react.ts +49 -0
  134. package/src/adapters/solid.ts +64 -0
  135. package/src/adapters/svelte-session.ts +21 -0
  136. package/src/adapters/svelte-webauthn.ts +20 -0
  137. package/src/adapters/svelte.ts +5 -0
  138. package/src/adapters/vue.ts +70 -0
  139. package/src/build/access-tokens.ts +44 -0
  140. package/src/build/client.ts +16 -0
  141. package/src/build/dev-key.ts +29 -0
  142. package/src/build/email.ts +32 -0
  143. package/src/build/guards.ts +12 -0
  144. package/src/build/module-entry.ts +8 -0
  145. package/src/build/oauth.ts +54 -0
  146. package/src/build/session.ts +54 -0
  147. package/src/build/single-use.ts +104 -0
  148. package/src/build/webauthn.ts +28 -0
  149. package/src/client/webauthn.ts +129 -0
  150. package/src/env.d.ts +84 -0
  151. package/src/index.ts +44 -0
  152. package/src/middleware.ts +9 -0
  153. package/src/module.ts +26 -0
  154. package/src/options.ts +241 -0
  155. package/src/route-middleware.ts +2 -0
  156. package/src/runtime/middleware/auth.ts +16 -0
  157. package/src/runtime/middleware/guest.ts +17 -0
  158. package/src/runtime/payload.ts +40 -0
  159. package/src/runtime/plugin.ts +12 -0
  160. package/src/runtime/store.ts +72 -0
  161. package/src/runtime/targets.ts +9 -0
  162. package/src/server/access-token.ts +130 -0
  163. package/src/server/auth-link.ts +95 -0
  164. package/src/server/door.ts +33 -0
  165. package/src/server/endpoint.ts +33 -0
  166. package/src/server/guard.ts +41 -0
  167. package/src/server/hooks.ts +13 -0
  168. package/src/server/index.ts +96 -0
  169. package/src/server/oauth/atproto-dns.ts +3 -0
  170. package/src/server/oauth/atproto-fetch.ts +67 -0
  171. package/src/server/oauth/atproto-metadata.ts +20 -0
  172. package/src/server/oauth/atproto.ts +292 -0
  173. package/src/server/oauth/cookie.ts +38 -0
  174. package/src/server/oauth/dpop.ts +32 -0
  175. package/src/server/oauth/handler.ts +377 -0
  176. package/src/server/oauth/oidc.ts +283 -0
  177. package/src/server/oauth/providers/apple.ts +108 -0
  178. package/src/server/oauth/providers/atlassian.ts +20 -0
  179. package/src/server/oauth/providers/auth0.ts +29 -0
  180. package/src/server/oauth/providers/authentik.ts +29 -0
  181. package/src/server/oauth/providers/azureb2c.ts +41 -0
  182. package/src/server/oauth/providers/battledotnet.ts +21 -0
  183. package/src/server/oauth/providers/box.ts +19 -0
  184. package/src/server/oauth/providers/catalog.ts +73 -0
  185. package/src/server/oauth/providers/cloudflare.ts +34 -0
  186. package/src/server/oauth/providers/cognito.ts +29 -0
  187. package/src/server/oauth/providers/discord.ts +19 -0
  188. package/src/server/oauth/providers/dropbox.ts +26 -0
  189. package/src/server/oauth/providers/facebook.ts +19 -0
  190. package/src/server/oauth/providers/gitea.ts +29 -0
  191. package/src/server/oauth/providers/github.ts +33 -0
  192. package/src/server/oauth/providers/gitlab.ts +29 -0
  193. package/src/server/oauth/providers/google.ts +19 -0
  194. package/src/server/oauth/providers/heroku.ts +28 -0
  195. package/src/server/oauth/providers/hubspot.ts +27 -0
  196. package/src/server/oauth/providers/instagram.ts +32 -0
  197. package/src/server/oauth/providers/keycloak.ts +31 -0
  198. package/src/server/oauth/providers/kick.ts +26 -0
  199. package/src/server/oauth/providers/line.ts +19 -0
  200. package/src/server/oauth/providers/linear.ts +34 -0
  201. package/src/server/oauth/providers/linkedin.ts +20 -0
  202. package/src/server/oauth/providers/livechat.ts +19 -0
  203. package/src/server/oauth/providers/mastodon.ts +29 -0
  204. package/src/server/oauth/providers/microsoft.ts +29 -0
  205. package/src/server/oauth/providers/okta.ts +29 -0
  206. package/src/server/oauth/providers/ory.ts +29 -0
  207. package/src/server/oauth/providers/osu.ts +19 -0
  208. package/src/server/oauth/providers/paypal.ts +19 -0
  209. package/src/server/oauth/providers/polar.ts +19 -0
  210. package/src/server/oauth/providers/preset.ts +206 -0
  211. package/src/server/oauth/providers/riotgames.ts +19 -0
  212. package/src/server/oauth/providers/roblox.ts +19 -0
  213. package/src/server/oauth/providers/salesforce.ts +29 -0
  214. package/src/server/oauth/providers/seznam.ts +19 -0
  215. package/src/server/oauth/providers/shopifyCustomer.ts +47 -0
  216. package/src/server/oauth/providers/slack.ts +27 -0
  217. package/src/server/oauth/providers/spotify.ts +19 -0
  218. package/src/server/oauth/providers/steam.ts +162 -0
  219. package/src/server/oauth/providers/strava.ts +20 -0
  220. package/src/server/oauth/providers/tiktok.ts +22 -0
  221. package/src/server/oauth/providers/twitch.ts +32 -0
  222. package/src/server/oauth/providers/vk.ts +36 -0
  223. package/src/server/oauth/providers/wechat.ts +39 -0
  224. package/src/server/oauth/providers/workos.ts +19 -0
  225. package/src/server/oauth/providers/x.ts +19 -0
  226. package/src/server/oauth/providers/xsuaa.ts +29 -0
  227. package/src/server/oauth/providers/yandex.ts +26 -0
  228. package/src/server/oauth/providers/zendesk.ts +29 -0
  229. package/src/server/oauth/providers/zitadel.ts +29 -0
  230. package/src/server/personal.ts +17 -0
  231. package/src/server/session.ts +150 -0
  232. package/src/server/token-requests.ts +13 -0
  233. package/src/server/token.ts +81 -0
  234. package/src/server/totp.ts +165 -0
  235. package/src/server/webauthn/cbor.ts +154 -0
  236. package/src/server/webauthn/cose.ts +95 -0
  237. package/src/server/webauthn/data.ts +50 -0
  238. package/src/server/webauthn/handler.ts +510 -0
  239. package/src/single-use.ts +41 -0
  240. package/src/types.ts +91 -0
@@ -0,0 +1,2 @@
1
+ export { default as auth } from "./runtime/middleware/auth.ts"
2
+ export { default as guest } from "./runtime/middleware/guest.ts"
@@ -0,0 +1,16 @@
1
+ /// <reference path="../../env.d.ts" />
2
+ import { redirect as targets } from "#hamur/auth/guards"
3
+ import { defineRouteMiddleware, redirect } from "hamur/app"
4
+ import { authStore } from "../store.ts"
5
+ import { loginTarget } from "../targets.ts"
6
+
7
+ /** A logged-out navigation goes to `auth.redirect.login?redirect=<app path>`. It steers navigation; it protects no data. */
8
+ export default defineRouteMiddleware(async (to, _from, { app, event }) => {
9
+ const store = authStore(app)
10
+ if (!store.get().ready) {
11
+ if (event) return
12
+ await store.fetch()
13
+ }
14
+ if (store.get().loggedIn) return
15
+ return redirect(loginTarget(targets.login, to.fullPath))
16
+ })
@@ -0,0 +1,17 @@
1
+ /// <reference path="../../env.d.ts" />
2
+ import { redirect as targets } from "#hamur/auth/guards"
3
+ import { defineRouteMiddleware, redirect } from "hamur/app"
4
+ import { authStore } from "../store.ts"
5
+ import { isAppPath } from "../targets.ts"
6
+
7
+ /** A logged-in navigation goes to the `redirect` query when it is an app path, else to `auth.redirect.home`. */
8
+ export default defineRouteMiddleware(async (to, _from, { app, event }) => {
9
+ const store = authStore(app)
10
+ if (!store.get().ready) {
11
+ if (event) return
12
+ await store.fetch()
13
+ }
14
+ if (!store.get().loggedIn) return
15
+ const wanted = to.query.redirect
16
+ return redirect(isAppPath(wanted) ? wanted : targets.home)
17
+ })
@@ -0,0 +1,40 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { loadStrategy } from "#hamur/auth/client"
3
+ import { definePlugin } from "hamur/app"
4
+ import { appendHeader, isCacheFork, setHeader, useLogger, type HamurEvent } from "hamur/server"
5
+ import { publicSession } from "../server/endpoint.ts"
6
+ import { markPersonal } from "../server/personal.ts"
7
+ import type { AuthPayload } from "./store.ts"
8
+
9
+ const logged = new Set<string>()
10
+
11
+ /** A prerendered or cached render is shared by every visitor and has no cookie, so it reads no session. */
12
+ function anonymous(event: HamurEvent): boolean {
13
+ return import.meta.prerender === true || isCacheFork(event)
14
+ }
15
+
16
+ export default definePlugin(async (app) => {
17
+ const { event } = app
18
+ if (loadStrategy !== "server-first" || !event || anonymous(event)) return
19
+ let session
20
+ try {
21
+ session = await publicSession(event)
22
+ } catch (error) {
23
+ const message = error instanceof Error ? error.message : String(error)
24
+ if (!logged.has(message)) {
25
+ logged.add(message)
26
+ useLogger(event).error(
27
+ error,
28
+ `@hamur/auth could not read the session for the page render, so the client fetches it: ${message}`,
29
+ { tag: "auth" },
30
+ )
31
+ }
32
+ return
33
+ }
34
+ const read = Object.keys(session).length ? session : null
35
+ app.modulePayload.auth = { session: read } satisfies AuthPayload
36
+ if (!read) return
37
+ markPersonal(event)
38
+ setHeader(event, "cache-control", "private, no-store")
39
+ appendHeader(event, "vary", "Cookie")
40
+ })
@@ -0,0 +1,12 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { fetchAfterMount } from "#hamur/auth/client"
3
+ import { definePlugin } from "hamur/app"
4
+ import { authStore } from "./store.ts"
5
+
6
+ export default definePlugin((app) => {
7
+ if (!fetchAfterMount) return
8
+ app.hooks.hookOnce("app:mounted", () => {
9
+ const store = authStore(app)
10
+ if (!store.get().ready) store.fetch().catch(() => {})
11
+ })
12
+ })
@@ -0,0 +1,72 @@
1
+ import { $fetch, type AppContext } from "hamur/app"
2
+ import type { PublicUserSession, User } from "../index.ts"
3
+
4
+ export const SESSION_PATH = "/_hamur/auth/session"
5
+
6
+ /** What `useUserSession` shows; `ready` is false until the session was read on the server or fetched. */
7
+ export interface UserSessionState {
8
+ ready: boolean
9
+ loggedIn: boolean
10
+ user: User | null
11
+ session: PublicUserSession | null
12
+ }
13
+
14
+ /** What `AuthState` hands its children once `ready`. */
15
+ export interface AuthStateSlot {
16
+ loggedIn: boolean
17
+ user: User | null
18
+ clear(): Promise<void>
19
+ }
20
+
21
+ export interface AuthStore {
22
+ get(): UserSessionState
23
+ subscribe(listener: () => void): () => void
24
+ fetch(): Promise<void>
25
+ clear(): Promise<void>
26
+ }
27
+
28
+ /** `{ session }` under `auth`, `null` when the server read the cookie and found an empty session; absent when it did not read it. */
29
+ export interface AuthPayload {
30
+ session: PublicUserSession | null
31
+ }
32
+
33
+ const stores = new WeakMap<AppContext, AuthStore>()
34
+
35
+ function stateOf(ready: boolean, found: PublicUserSession | null | undefined): UserSessionState {
36
+ const session = found && Object.keys(found).length ? found : null
37
+ const user = (session?.user as User | undefined) ?? null
38
+ return { ready, loggedIn: user !== null, user, session }
39
+ }
40
+
41
+ /** One store per app context, started from the module payload, so the server render and the hydration read the same state. */
42
+ export function authStore(app: AppContext): AuthStore {
43
+ let store = stores.get(app)
44
+ if (store) return store
45
+ const payload = app.modulePayload.auth as AuthPayload | undefined
46
+ let state = stateOf(payload !== undefined, payload?.session)
47
+ let run = 0
48
+ const listeners = new Set<() => void>()
49
+ const set = (next: UserSessionState) => {
50
+ state = next
51
+ for (const listener of [...listeners]) listener()
52
+ }
53
+ store = {
54
+ get: () => state,
55
+ subscribe(listener) {
56
+ listeners.add(listener)
57
+ return () => void listeners.delete(listener)
58
+ },
59
+ async fetch() {
60
+ const current = ++run
61
+ const session = await $fetch<PublicUserSession>(SESSION_PATH, { retry: 0 })
62
+ if (current === run) set(stateOf(true, session))
63
+ },
64
+ async clear() {
65
+ const current = ++run
66
+ await $fetch(SESSION_PATH, { method: "DELETE" })
67
+ if (current === run) set(stateOf(true, null))
68
+ },
69
+ }
70
+ stores.set(app, store)
71
+ return store
72
+ }
@@ -0,0 +1,9 @@
1
+ /** A path on this origin: `/` and then not `/` or `\`, so no scheme and no host; no control character, which a browser drops before it reads the URL. */
2
+ export function isAppPath(value: unknown): value is string {
3
+ return typeof value === "string" && /^\/(?![/\\])/.test(value) && !/[\x00-\x1f\x7f]/.test(value)
4
+ }
5
+
6
+ /** `auth.redirect.login` with `redirect=<the app path asked for>` added to its query. */
7
+ export function loginTarget(login: string, path: string): string {
8
+ return `${login}?redirect=${encodeURIComponent(path)}`
9
+ }
@@ -0,0 +1,130 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { accessTokens } from "#hamur/auth/access-tokens"
3
+ import { createError, noStore, type FunctionMiddleware, type HamurEvent } from "hamur/server"
4
+ import { isCacheFork, perCaller, sha256Hex, timingSafeEqual, toBase64Url, withIdentity } from "hamur/server/internal"
5
+ import type { AccessToken, User } from "../index.ts"
6
+ import { requireUserSession } from "./session.ts"
7
+ import { noteTokenRequest } from "./token-requests.ts"
8
+
9
+ const TOKEN = /^hamur_([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})_([A-Za-z0-9_-]{43})$/
10
+ const NO_ID = "00000000-0000-0000-0000-000000000000"
11
+ const NO_HASH = "0".repeat(64)
12
+ const USED_EVERY = 60_000
13
+
14
+ export interface AccessTokenOptions {
15
+ /** What the user calls the token, such as `"deploy script"`. */
16
+ name: string
17
+ /** Seconds until the token stops working, a positive integer; without it the token works until it is revoked. */
18
+ expiresIn?: number
19
+ /** What the token may be used for, such as `["reports:read"]`; the app's policies and handlers read them. Default `[]`. */
20
+ scopes?: string[]
21
+ }
22
+
23
+ /** What `requireAccessToken` puts on the context. */
24
+ export interface RequiredAccessToken {
25
+ accessToken: AccessToken
26
+ user: User
27
+ }
28
+
29
+ interface Row {
30
+ id: string
31
+ user_id: string
32
+ token_hash: string
33
+ scopes: string
34
+ expires_at: string | null
35
+ last_used_at: string | null
36
+ }
37
+
38
+ const shown = (value: unknown): string => (typeof value === "string" ? JSON.stringify(value) : String(value))
39
+ const iso = (time: number): string => new Date(time).toISOString()
40
+ const isText = (value: unknown): value is string => typeof value === "string" && value !== ""
41
+
42
+ function configured(): NonNullable<typeof accessTokens> {
43
+ if (!accessTokens) throw new Error("@hamur/auth: access tokens need auth.accessTokens.user in hamur.config.ts")
44
+ return accessTokens
45
+ }
46
+
47
+ const database = async () => (await configured().loadDb()).useDatabase()
48
+
49
+ async function sessionUserId(event: HamurEvent): Promise<string> {
50
+ const { id } = (await requireUserSession(event)).user as { id?: unknown }
51
+ if (isText(id) || typeof id === "number") return String(id)
52
+ throw new TypeError("@hamur/auth: access tokens need the session user's id, a non-empty string or a number")
53
+ }
54
+
55
+ /** A token for the session's user, returned here once; only the SHA-256 of its secret part is stored. */
56
+ export async function createAccessToken(
57
+ event: HamurEvent,
58
+ options: AccessTokenOptions,
59
+ ): Promise<{ id: string; token: string }> {
60
+ const { name, expiresIn, scopes = [] } = options
61
+ if (!isText(name)) throw new TypeError(`createAccessToken name must be a non-empty string (got ${shown(name)})`)
62
+ if (expiresIn !== undefined && !(Number.isSafeInteger(expiresIn) && expiresIn > 0))
63
+ throw new TypeError(`createAccessToken expiresIn must be a positive integer of seconds (got ${shown(expiresIn)})`)
64
+ if (!Array.isArray(scopes) || !scopes.every(isText))
65
+ throw new TypeError("createAccessToken scopes must be an array of non-empty strings")
66
+ const userId = await sessionUserId(event)
67
+ const db = await database()
68
+ const id = crypto.randomUUID()
69
+ const secret = toBase64Url(crypto.getRandomValues(new Uint8Array(32)))
70
+ const hash = await sha256Hex(secret)
71
+ const now = Date.now()
72
+ const expiresAt = expiresIn === undefined ? null : iso(now + expiresIn * 1000)
73
+ await db.run`insert into access_tokens (id, user_id, name, token_hash, scopes, expires_at, last_used_at, created_at)
74
+ values (${id}, ${userId}, ${name}, ${hash}, ${JSON.stringify(scopes)}, ${expiresAt}, ${null}, ${iso(now)})`
75
+ return { id, token: `hamur_${id}_${secret}` }
76
+ }
77
+
78
+ /** Deletes the token `id` of the session's user; another user's token and an unknown id are left as they are. */
79
+ export async function revokeAccessToken(event: HamurEvent, id: string): Promise<void> {
80
+ const userId = await sessionUserId(event)
81
+ const db = await database()
82
+ await db.run`delete from access_tokens where id = ${id} and user_id = ${userId}`
83
+ }
84
+
85
+ function refuse(event: HamurEvent, challenge: string): never {
86
+ event.response.headers.set("www-authenticate", challenge)
87
+ throw createError({ status: 401, message: "Unauthorized" })
88
+ }
89
+
90
+ /** Every refused token takes one hash, one lookup by id and one comparison, so its time does not say why it was refused. */
91
+ async function authenticate(event: HamurEvent): Promise<RequiredAccessToken> {
92
+ noStore(event)
93
+ const bearer = /^bearer(?: +(.*))?$/i.exec(event.request.headers.get("authorization")?.trim() ?? "")
94
+ if (!bearer) return refuse(event, "Bearer")
95
+ const [, id = NO_ID, secret = ""] = TOKEN.exec(bearer[1] ?? "") ?? []
96
+ const db = await database()
97
+ const hash = await sha256Hex(secret)
98
+ const row = await db.first<Row>`select id, user_id, token_hash, scopes, expires_at, last_used_at
99
+ from access_tokens where id = ${id}`
100
+ const now = Date.now()
101
+ const matches = timingSafeEqual(hash, row?.token_hash ?? NO_HASH)
102
+ const current = !row?.expires_at || new Date(row.expires_at).getTime() > now
103
+ if (!row || !matches || !current) return refuse(event, 'Bearer error="invalid_token"')
104
+ const { default: userOf } = await configured().loadUser()
105
+ const user = await userOf(String(row.user_id))
106
+ if (!user) return refuse(event, 'Bearer error="invalid_token"')
107
+ const before = now - USED_EVERY
108
+ if (!row.last_used_at || new Date(row.last_used_at).getTime() <= before)
109
+ await db.run`update access_tokens set last_used_at = ${iso(now)}
110
+ where id = ${row.id} and (last_used_at is null or last_used_at <= ${iso(before)})`
111
+ return { accessToken: { id: row.id, scopes: JSON.parse(row.scopes) as string[] }, user }
112
+ }
113
+
114
+ /**
115
+ * The `server` part of `requireAccessToken`. `authorize` and `principal` get the event, so `event.context` holds the token too,
116
+ * for this call alone; in a request list, whose `context` is `event.context`, `next({ context })` would leave it there.
117
+ */
118
+ export const accessTokenGuard: NonNullable<FunctionMiddleware<{}, RequiredAccessToken>["server"]> = perCaller(
119
+ async ({ event, context, next }) => {
120
+ if (isCacheFork(event))
121
+ throw new Error(
122
+ "@hamur/auth: requireAccessToken cannot be used with cache or prerender: a stored answer is not checked",
123
+ )
124
+ const required = await authenticate(event)
125
+ noteTokenRequest(event)
126
+ return withIdentity(event, { ...required }, () =>
127
+ next(context === event.context ? undefined : { context: required }),
128
+ )
129
+ },
130
+ )
@@ -0,0 +1,95 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { email as configured, loadMail, siteUrl, templates } from "#hamur/auth/email"
3
+ import { baseURL } from "#hamur/auth/guards"
4
+ import { useSiteConfig, type HamurEvent } from "hamur/server"
5
+ import { absoluteUrl, escapeXml } from "hamur/server/internal"
6
+ import { isAppPath } from "../runtime/targets.ts"
7
+ import type { AuthLinkPurpose } from "../types.ts"
8
+ import { createAuthToken } from "./token.ts"
9
+
10
+ const TEXT: Record<AuthLinkPurpose, { subject(site: string): string; intro(site: string): string; action: string }> = {
11
+ "magic-link": {
12
+ subject: (site) => `Sign in to ${site}`,
13
+ intro: (site) => `Use this link to sign in to ${site}:`,
14
+ action: "Sign in",
15
+ },
16
+ "verify-email": {
17
+ subject: () => "Confirm your email",
18
+ intro: (site) => `Use this link to confirm your email address for ${site}:`,
19
+ action: "Confirm your email",
20
+ },
21
+ "password-reset": {
22
+ subject: () => "Reset your password",
23
+ intro: (site) => `Use this link to set a new password for ${site}:`,
24
+ action: "Reset your password",
25
+ },
26
+ }
27
+
28
+ /** The shape of one address, without a character JSON escapes, so `redacted` finds it in an error; `sendMail` checks the rest. */
29
+ const ADDRESS = /^[^\s@"\\\x00-\x1f\x7f]+@[^\s@"\\\x00-\x1f\x7f]+$/
30
+
31
+ function body(purpose: AuthLinkPurpose, site: string, url: string, expiresAt: Date): string {
32
+ const { intro, action } = TEXT[purpose]
33
+ const until = expiresAt.toISOString().slice(0, 16).replace("T", " ")
34
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"></head><body><p>${escapeXml(intro(site))}</p><p><a href="${escapeXml(url)}">${action}</a></p><p>The link works once, until ${until} UTC. If you did not ask for it, ignore this email.</p></body></html>`
35
+ }
36
+
37
+ /** `sendMail` quotes an address it refuses and a mail server may quote the link; neither may reach the app's log. */
38
+ function redacted(error: unknown, token: string, email: string): unknown {
39
+ for (let at = error; at instanceof Error; at = at.cause) {
40
+ const text = `${at.message}\n${at.stack}`
41
+ if (text.includes(token) || text.includes(email))
42
+ return new Error((error as Error).message.replaceAll(token, "<token>").replaceAll(email, "<email>"))
43
+ }
44
+ return error
45
+ }
46
+
47
+ /**
48
+ * Mails `email` a link of `auth.email.<purpose>` with a single-use token; the page posts the token to a handler that calls
49
+ * `consumeAuthToken(event, token, purpose)`, which gives `{ email, data, next }`. It looks no account up: the app decides whether to send.
50
+ */
51
+ export async function sendAuthLink(
52
+ event: HamurEvent,
53
+ options: {
54
+ purpose: AuthLinkPurpose
55
+ /** One bare address, such as `"ada@example.com"`. */
56
+ email: string
57
+ /** Sealed into the token. */
58
+ data?: unknown
59
+ /** An app path, sealed into the token. */
60
+ next?: string
61
+ },
62
+ ): Promise<void> {
63
+ const { purpose, email, data, next } = options
64
+ if (!Object.hasOwn(TEXT, purpose))
65
+ throw new TypeError(
66
+ `sendAuthLink purpose must be "magic-link", "verify-email" or "password-reset" (got ${JSON.stringify(purpose)})`,
67
+ )
68
+ if (typeof email !== "string" || !email.isWellFormed() || !ADDRESS.test(email))
69
+ throw new TypeError("sendAuthLink email must be one bare address")
70
+ if (next !== undefined && !isAppPath(next))
71
+ throw new TypeError(`sendAuthLink next must be an app path such as "/account" (got ${JSON.stringify(next)})`)
72
+ if (!loadMail) throw new Error("@hamur/auth: sendAuthLink needs @hamur/mail in modules")
73
+ const site = useSiteConfig(event)
74
+ const origin = site.url ?? siteUrl
75
+ if (!origin) throw new Error("@hamur/auth: sendAuthLink needs site.url: a mail holds absolute links")
76
+
77
+ const { page, template, subject, ttl } = configured[purpose]
78
+ const expiresAt = new Date(Date.now() + ttl * 1000)
79
+ const token = await createAuthToken(event, { purpose, data: { email, data, next }, ttl })
80
+ const url = `${absoluteUrl(origin, baseURL, page)}?token=${token}`
81
+ const name = site.name ?? new URL(origin).host
82
+ const { sendMail } = await loadMail()
83
+ try {
84
+ await sendMail({
85
+ // an object takes one bare address: no list, no display name
86
+ to: { address: email },
87
+ subject: subject ?? TEXT[purpose].subject(name),
88
+ ...(templates.includes(template)
89
+ ? { template, props: { url, email, expiresAt } }
90
+ : { html: body(purpose, name, url, expiresAt) }),
91
+ })
92
+ } catch (error) {
93
+ throw redacted(error, token, email)
94
+ }
95
+ }
@@ -0,0 +1,33 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { session as configured } from "#hamur/auth/options"
3
+ import { singleUse } from "#hamur/auth/single-use"
4
+ import { webauthn } from "#hamur/auth/webauthn"
5
+ import { definePlugin, defineServer, unseal, useLogger } from "hamur/server"
6
+ import { inProcessWarning } from "../single-use.ts"
7
+ import { setServerHooks } from "./hooks.ts"
8
+ import { withPersonalHeaders } from "./personal.ts"
9
+ import { diagnostic } from "hamur/server/internal"
10
+
11
+ export { authSession, authSessionClear } from "./endpoint.ts"
12
+ export { atprotoClientMetadata } from "./oauth/atproto-metadata.ts"
13
+
14
+ export default defineServer({
15
+ plugins: [
16
+ definePlugin(async (server) => {
17
+ setServerHooks(server.hooks)
18
+ server.hooks.hook("beforeResponse", withPersonalHeaders)
19
+ if (import.meta.dev || import.meta.prerender) return
20
+ if (webauthn.used && webauthn.rpID === undefined && !webauthn.listedHosts)
21
+ throw new Error("@hamur/auth: webauthn needs auth.webauthn.rpID or server.allowedHosts in production")
22
+ if (singleUse.inProcess !== undefined)
23
+ useLogger()
24
+ .child({ name: "auth" })
25
+ .warn(diagnostic("HAMUR_W5106", inProcessWarning(singleUse.inProcess)))
26
+ if (configured.password !== undefined) return
27
+ // unseal reads the app key before it reads its input, and throws only when the server has none
28
+ await unseal("").catch(() => {
29
+ throw new Error("@hamur/auth needs HAMUR_KEY (run hamur create-key --env, or set it in the deployment)")
30
+ })
31
+ }),
32
+ ],
33
+ })
@@ -0,0 +1,33 @@
1
+ import { appendHeader, defineHandler, setHeader, type HamurEvent } from "hamur/server"
2
+ import type { PublicUserSession } from "../index.ts"
3
+ import { serverHooks } from "./hooks.ts"
4
+ import { clearUserSession, getUserSession } from "./session.ts"
5
+
6
+ /** The session without `id` and `secure`, after `auth:session:fetch` when it has keys; the endpoint and the render payload send it. */
7
+ export async function publicSession(event: HamurEvent): Promise<PublicUserSession> {
8
+ const { id: _id, secure: _secure, ...session } = await getUserSession(event)
9
+ const answer: PublicUserSession = session
10
+ if (Object.keys(answer).length) await serverHooks()?.callHook("auth:session:fetch", answer, event)
11
+ return answer
12
+ }
13
+
14
+ export const authSession = defineHandler({
15
+ route: "/_hamur/auth/session",
16
+ method: "GET",
17
+ raw: true,
18
+ async handler(_, { event }) {
19
+ setHeader(event, "cache-control", "private, no-store")
20
+ appendHeader(event, "vary", "Cookie")
21
+ return publicSession(event)
22
+ },
23
+ })
24
+
25
+ export const authSessionClear = defineHandler({
26
+ route: "/_hamur/auth/session",
27
+ method: "DELETE",
28
+ raw: true,
29
+ async handler(_, { event }) {
30
+ await clearUserSession(event)
31
+ return new Response(null, { status: 204 })
32
+ },
33
+ })
@@ -0,0 +1,41 @@
1
+ /// <reference path="../env.d.ts" />
2
+ import { baseURL, redirect as targets } from "#hamur/auth/guards"
3
+ import { redirect } from "hamur/app"
4
+ import { getRequestURL, isHamurError, prefersHtml, type FunctionMiddleware } from "hamur/server"
5
+ import type { User, UserSessionData } from "../index.ts"
6
+ import { loginTarget } from "../runtime/targets.ts"
7
+ import { requireUserSession } from "./session.ts"
8
+
9
+ /** What `requireUser` puts on the context. */
10
+ export interface RequiredUser {
11
+ user: User
12
+ session: UserSessionData & { user: User; id: string }
13
+ }
14
+
15
+ /** A `GET` or `HEAD` that prefers HTML; a WebSocket upgrade never is one, whatever its `Accept`. */
16
+ function isDocument(request: Request): boolean {
17
+ if (request.headers.get("upgrade")?.toLowerCase() === "websocket") return false
18
+ return (request.method === "GET" || request.method === "HEAD") && prefersHtml(request)
19
+ }
20
+
21
+ function appPath(url: URL): string {
22
+ const base = baseURL.replace(/\/+$/, "")
23
+ const path =
24
+ base && (url.pathname === base || url.pathname.startsWith(`${base}/`))
25
+ ? url.pathname.slice(base.length) || "/"
26
+ : url.pathname
27
+ return `${path}${url.search}`
28
+ }
29
+
30
+ /** The `server` part of `requireUser`. In a request list (its `context` is `event.context`) a document request goes to the login page; anything else is the 401. */
31
+ export const guard: NonNullable<FunctionMiddleware<{}, RequiredUser>["server"]> = async ({ event, context, next }) => {
32
+ let session: RequiredUser["session"]
33
+ try {
34
+ session = await requireUserSession(event)
35
+ } catch (error) {
36
+ if (isHamurError(error) && error.status === 401 && context === event.context && isDocument(event.request))
37
+ throw redirect(loginTarget(targets.login, appPath(getRequestURL(event))))
38
+ throw error
39
+ }
40
+ return next({ context: { user: session.user, session } })
41
+ }
@@ -0,0 +1,13 @@
1
+ import type { Hooks } from "hamur/kit"
2
+ import type { ServerHooks } from "hamur/server"
3
+
4
+ let current: Hooks<ServerHooks> | undefined
5
+
6
+ /** The door's plugin hands over the server's hooks at start, before any request. */
7
+ export function setServerHooks(hooks: Hooks<ServerHooks>): void {
8
+ current = hooks
9
+ }
10
+
11
+ export function serverHooks(): Hooks<ServerHooks> | undefined {
12
+ return current
13
+ }
@@ -0,0 +1,96 @@
1
+ export { clearUserSession, getUserSession, replaceUserSession, requireUserSession, setUserSession } from "./session.ts"
2
+ export { createAccessToken, revokeAccessToken } from "./access-token.ts"
3
+ export type { AccessTokenOptions } from "./access-token.ts"
4
+ export { sendAuthLink } from "./auth-link.ts"
5
+ export { consumeAuthToken, createAuthToken } from "./token.ts"
6
+ export type { AuthTokenOptions } from "./token.ts"
7
+ export { createRecoveryCodes, createTotp, matchRecoveryCode, verifyTotp } from "./totp.ts"
8
+ export type { TotpOptions, VerifyTotpOptions } from "./totp.ts"
9
+ export { oauthHandler } from "./oauth/handler.ts"
10
+ export type { OAuthError, OAuthHandlerOptions, OAuthTokens } from "./oauth/handler.ts"
11
+ export { oauthOIDC } from "./oauth/oidc.ts"
12
+ export type { OAuthOIDCOptions } from "./oauth/oidc.ts"
13
+ export { oauthAtproto } from "./oauth/atproto.ts"
14
+ export type { AtprotoClientMetadata, AtprotoResult, OAuthAtprotoOptions } from "./oauth/atproto.ts"
15
+ export type { OAuthPresetBaseOptions, OAuthPresetOptions } from "./oauth/providers/preset.ts"
16
+ export { oauthApple } from "./oauth/providers/apple.ts"
17
+ export type { AppleConfig, AppleUser } from "./oauth/providers/apple.ts"
18
+ export { oauthDiscord } from "./oauth/providers/discord.ts"
19
+ export { oauthGitHub } from "./oauth/providers/github.ts"
20
+ export { oauthGitLab } from "./oauth/providers/gitlab.ts"
21
+ export type { GitLabConfig } from "./oauth/providers/gitlab.ts"
22
+ export { oauthGoogle } from "./oauth/providers/google.ts"
23
+ export { oauthMicrosoft } from "./oauth/providers/microsoft.ts"
24
+ export type { MicrosoftConfig } from "./oauth/providers/microsoft.ts"
25
+ export { oauthSteam } from "./oauth/providers/steam.ts"
26
+ export type { SteamOptions, SteamUser } from "./oauth/providers/steam.ts"
27
+ export { oauthAtlassian } from "./oauth/providers/atlassian.ts"
28
+ export { oauthAuth0 } from "./oauth/providers/auth0.ts"
29
+ export type { Auth0Config } from "./oauth/providers/auth0.ts"
30
+ export { oauthAuthentik } from "./oauth/providers/authentik.ts"
31
+ export type { AuthentikConfig } from "./oauth/providers/authentik.ts"
32
+ export { oauthBattleDotNet } from "./oauth/providers/battledotnet.ts"
33
+ export { oauthBox } from "./oauth/providers/box.ts"
34
+ export { oauthDropbox } from "./oauth/providers/dropbox.ts"
35
+ export { oauthFacebook } from "./oauth/providers/facebook.ts"
36
+ export { oauthGitea } from "./oauth/providers/gitea.ts"
37
+ export type { GiteaConfig } from "./oauth/providers/gitea.ts"
38
+ export { oauthHeroku } from "./oauth/providers/heroku.ts"
39
+ export { oauthKeycloak } from "./oauth/providers/keycloak.ts"
40
+ export type { KeycloakConfig } from "./oauth/providers/keycloak.ts"
41
+ export { oauthKick } from "./oauth/providers/kick.ts"
42
+ export { oauthLine } from "./oauth/providers/line.ts"
43
+ export { oauthLinear } from "./oauth/providers/linear.ts"
44
+ export { oauthLinkedIn } from "./oauth/providers/linkedin.ts"
45
+ export { oauthMastodon } from "./oauth/providers/mastodon.ts"
46
+ export type { MastodonConfig } from "./oauth/providers/mastodon.ts"
47
+ export { oauthOkta } from "./oauth/providers/okta.ts"
48
+ export type { OktaConfig } from "./oauth/providers/okta.ts"
49
+ export { oauthOry } from "./oauth/providers/ory.ts"
50
+ export type { OryConfig } from "./oauth/providers/ory.ts"
51
+ export { oauthOsu } from "./oauth/providers/osu.ts"
52
+ export { oauthPayPal } from "./oauth/providers/paypal.ts"
53
+ export { oauthPolar } from "./oauth/providers/polar.ts"
54
+ export { oauthRiotGames } from "./oauth/providers/riotgames.ts"
55
+ export { oauthRoblox } from "./oauth/providers/roblox.ts"
56
+ export { oauthSalesforce } from "./oauth/providers/salesforce.ts"
57
+ export type { SalesforceConfig } from "./oauth/providers/salesforce.ts"
58
+ export { oauthSeznam } from "./oauth/providers/seznam.ts"
59
+ export { oauthSlack } from "./oauth/providers/slack.ts"
60
+ export { oauthSpotify } from "./oauth/providers/spotify.ts"
61
+ export { oauthTwitch } from "./oauth/providers/twitch.ts"
62
+ export { oauthX } from "./oauth/providers/x.ts"
63
+ export { oauthYandex } from "./oauth/providers/yandex.ts"
64
+ export { oauthZendesk } from "./oauth/providers/zendesk.ts"
65
+ export type { ZendeskConfig } from "./oauth/providers/zendesk.ts"
66
+ export { oauthZitadel } from "./oauth/providers/zitadel.ts"
67
+ export type { ZitadelConfig } from "./oauth/providers/zitadel.ts"
68
+ export { oauthAzureB2C } from "./oauth/providers/azureb2c.ts"
69
+ export type { AzureB2CConfig } from "./oauth/providers/azureb2c.ts"
70
+ export { oauthCloudflare } from "./oauth/providers/cloudflare.ts"
71
+ export type { CloudflareConfig } from "./oauth/providers/cloudflare.ts"
72
+ export { oauthCognito } from "./oauth/providers/cognito.ts"
73
+ export type { CognitoConfig } from "./oauth/providers/cognito.ts"
74
+ export { oauthHubSpot } from "./oauth/providers/hubspot.ts"
75
+ export { oauthInstagram } from "./oauth/providers/instagram.ts"
76
+ export { oauthLiveChat } from "./oauth/providers/livechat.ts"
77
+ export { oauthShopifyCustomer } from "./oauth/providers/shopifyCustomer.ts"
78
+ export type { ShopifyCustomerConfig } from "./oauth/providers/shopifyCustomer.ts"
79
+ export { oauthStrava } from "./oauth/providers/strava.ts"
80
+ export { oauthTikTok } from "./oauth/providers/tiktok.ts"
81
+ export { oauthVK } from "./oauth/providers/vk.ts"
82
+ export { oauthWeChat } from "./oauth/providers/wechat.ts"
83
+ export { oauthWorkOS } from "./oauth/providers/workos.ts"
84
+ export { oauthXsuaa } from "./oauth/providers/xsuaa.ts"
85
+ export type { XsuaaConfig } from "./oauth/providers/xsuaa.ts"
86
+ export { webAuthnAuthenticate, webAuthnRegister } from "./webauthn/handler.ts"
87
+ export type {
88
+ WebAuthnAlgorithm,
89
+ WebAuthnAuthenticateOptions,
90
+ WebAuthnCredential,
91
+ WebAuthnCredentialDescriptor,
92
+ WebAuthnRegisterOptions,
93
+ WebAuthnUser,
94
+ WebAuthnUserVerification,
95
+ } from "./webauthn/handler.ts"
96
+ export type { UserSessionData } from "../index.ts"
@@ -0,0 +1,3 @@
1
+ import { pinnedFetch } from "hamur/server/internal"
2
+
3
+ export const hostFetch = pinnedFetch()