@_mustachio/openauth 0.6.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 (192) hide show
  1. package/dist/esm/client.js +186 -0
  2. package/dist/esm/css.d.js +0 -0
  3. package/dist/esm/error.js +73 -0
  4. package/dist/esm/index.js +14 -0
  5. package/dist/esm/issuer.js +558 -0
  6. package/dist/esm/jwt.js +16 -0
  7. package/dist/esm/keys.js +113 -0
  8. package/dist/esm/pkce.js +35 -0
  9. package/dist/esm/provider/apple.js +28 -0
  10. package/dist/esm/provider/arctic.js +43 -0
  11. package/dist/esm/provider/code.js +58 -0
  12. package/dist/esm/provider/cognito.js +16 -0
  13. package/dist/esm/provider/discord.js +15 -0
  14. package/dist/esm/provider/facebook.js +24 -0
  15. package/dist/esm/provider/github.js +15 -0
  16. package/dist/esm/provider/google.js +25 -0
  17. package/dist/esm/provider/index.js +3 -0
  18. package/dist/esm/provider/jumpcloud.js +15 -0
  19. package/dist/esm/provider/keycloak.js +15 -0
  20. package/dist/esm/provider/linkedin.js +15 -0
  21. package/dist/esm/provider/m2m.js +17 -0
  22. package/dist/esm/provider/microsoft.js +24 -0
  23. package/dist/esm/provider/oauth2.js +119 -0
  24. package/dist/esm/provider/oidc.js +69 -0
  25. package/dist/esm/provider/passkey.js +315 -0
  26. package/dist/esm/provider/password.js +306 -0
  27. package/dist/esm/provider/provider.js +10 -0
  28. package/dist/esm/provider/slack.js +15 -0
  29. package/dist/esm/provider/spotify.js +15 -0
  30. package/dist/esm/provider/twitch.js +15 -0
  31. package/dist/esm/provider/x.js +16 -0
  32. package/dist/esm/provider/yahoo.js +15 -0
  33. package/dist/esm/random.js +27 -0
  34. package/dist/esm/storage/aws.js +39 -0
  35. package/dist/esm/storage/cloudflare.js +42 -0
  36. package/dist/esm/storage/dynamo.js +116 -0
  37. package/dist/esm/storage/memory.js +88 -0
  38. package/dist/esm/storage/storage.js +36 -0
  39. package/dist/esm/subject.js +7 -0
  40. package/dist/esm/ui/base.js +407 -0
  41. package/dist/esm/ui/code.js +151 -0
  42. package/dist/esm/ui/form.js +43 -0
  43. package/dist/esm/ui/icon.js +92 -0
  44. package/dist/esm/ui/passkey.js +329 -0
  45. package/dist/esm/ui/password.js +338 -0
  46. package/dist/esm/ui/select.js +187 -0
  47. package/dist/esm/ui/theme.js +115 -0
  48. package/dist/esm/util.js +54 -0
  49. package/dist/types/client.d.ts +466 -0
  50. package/dist/types/client.d.ts.map +1 -0
  51. package/dist/types/error.d.ts +77 -0
  52. package/dist/types/error.d.ts.map +1 -0
  53. package/dist/types/index.d.ts +20 -0
  54. package/dist/types/index.d.ts.map +1 -0
  55. package/dist/types/issuer.d.ts +465 -0
  56. package/dist/types/issuer.d.ts.map +1 -0
  57. package/dist/types/jwt.d.ts +6 -0
  58. package/dist/types/jwt.d.ts.map +1 -0
  59. package/dist/types/keys.d.ts +18 -0
  60. package/dist/types/keys.d.ts.map +1 -0
  61. package/dist/types/pkce.d.ts +7 -0
  62. package/dist/types/pkce.d.ts.map +1 -0
  63. package/dist/types/provider/apple.d.ts +108 -0
  64. package/dist/types/provider/apple.d.ts.map +1 -0
  65. package/dist/types/provider/arctic.d.ts +16 -0
  66. package/dist/types/provider/arctic.d.ts.map +1 -0
  67. package/dist/types/provider/code.d.ts +74 -0
  68. package/dist/types/provider/code.d.ts.map +1 -0
  69. package/dist/types/provider/cognito.d.ts +64 -0
  70. package/dist/types/provider/cognito.d.ts.map +1 -0
  71. package/dist/types/provider/discord.d.ts +38 -0
  72. package/dist/types/provider/discord.d.ts.map +1 -0
  73. package/dist/types/provider/facebook.d.ts +74 -0
  74. package/dist/types/provider/facebook.d.ts.map +1 -0
  75. package/dist/types/provider/github.d.ts +38 -0
  76. package/dist/types/provider/github.d.ts.map +1 -0
  77. package/dist/types/provider/google.d.ts +74 -0
  78. package/dist/types/provider/google.d.ts.map +1 -0
  79. package/dist/types/provider/index.d.ts +4 -0
  80. package/dist/types/provider/index.d.ts.map +1 -0
  81. package/dist/types/provider/jumpcloud.d.ts +38 -0
  82. package/dist/types/provider/jumpcloud.d.ts.map +1 -0
  83. package/dist/types/provider/keycloak.d.ts +67 -0
  84. package/dist/types/provider/keycloak.d.ts.map +1 -0
  85. package/dist/types/provider/linkedin.d.ts +6 -0
  86. package/dist/types/provider/linkedin.d.ts.map +1 -0
  87. package/dist/types/provider/m2m.d.ts +34 -0
  88. package/dist/types/provider/m2m.d.ts.map +1 -0
  89. package/dist/types/provider/microsoft.d.ts +89 -0
  90. package/dist/types/provider/microsoft.d.ts.map +1 -0
  91. package/dist/types/provider/oauth2.d.ts +133 -0
  92. package/dist/types/provider/oauth2.d.ts.map +1 -0
  93. package/dist/types/provider/oidc.d.ts +91 -0
  94. package/dist/types/provider/oidc.d.ts.map +1 -0
  95. package/dist/types/provider/passkey.d.ts +143 -0
  96. package/dist/types/provider/passkey.d.ts.map +1 -0
  97. package/dist/types/provider/password.d.ts +210 -0
  98. package/dist/types/provider/password.d.ts.map +1 -0
  99. package/dist/types/provider/provider.d.ts +29 -0
  100. package/dist/types/provider/provider.d.ts.map +1 -0
  101. package/dist/types/provider/slack.d.ts +59 -0
  102. package/dist/types/provider/slack.d.ts.map +1 -0
  103. package/dist/types/provider/spotify.d.ts +38 -0
  104. package/dist/types/provider/spotify.d.ts.map +1 -0
  105. package/dist/types/provider/twitch.d.ts +38 -0
  106. package/dist/types/provider/twitch.d.ts.map +1 -0
  107. package/dist/types/provider/x.d.ts +38 -0
  108. package/dist/types/provider/x.d.ts.map +1 -0
  109. package/dist/types/provider/yahoo.d.ts +38 -0
  110. package/dist/types/provider/yahoo.d.ts.map +1 -0
  111. package/dist/types/random.d.ts +3 -0
  112. package/dist/types/random.d.ts.map +1 -0
  113. package/dist/types/storage/aws.d.ts +4 -0
  114. package/dist/types/storage/aws.d.ts.map +1 -0
  115. package/dist/types/storage/cloudflare.d.ts +34 -0
  116. package/dist/types/storage/cloudflare.d.ts.map +1 -0
  117. package/dist/types/storage/dynamo.d.ts +65 -0
  118. package/dist/types/storage/dynamo.d.ts.map +1 -0
  119. package/dist/types/storage/memory.d.ts +49 -0
  120. package/dist/types/storage/memory.d.ts.map +1 -0
  121. package/dist/types/storage/storage.d.ts +15 -0
  122. package/dist/types/storage/storage.d.ts.map +1 -0
  123. package/dist/types/subject.d.ts +122 -0
  124. package/dist/types/subject.d.ts.map +1 -0
  125. package/dist/types/ui/base.d.ts +5 -0
  126. package/dist/types/ui/base.d.ts.map +1 -0
  127. package/dist/types/ui/code.d.ts +104 -0
  128. package/dist/types/ui/code.d.ts.map +1 -0
  129. package/dist/types/ui/form.d.ts +6 -0
  130. package/dist/types/ui/form.d.ts.map +1 -0
  131. package/dist/types/ui/icon.d.ts +6 -0
  132. package/dist/types/ui/icon.d.ts.map +1 -0
  133. package/dist/types/ui/passkey.d.ts +5 -0
  134. package/dist/types/ui/passkey.d.ts.map +1 -0
  135. package/dist/types/ui/password.d.ts +139 -0
  136. package/dist/types/ui/password.d.ts.map +1 -0
  137. package/dist/types/ui/select.d.ts +55 -0
  138. package/dist/types/ui/select.d.ts.map +1 -0
  139. package/dist/types/ui/theme.d.ts +207 -0
  140. package/dist/types/ui/theme.d.ts.map +1 -0
  141. package/dist/types/util.d.ts +8 -0
  142. package/dist/types/util.d.ts.map +1 -0
  143. package/package.json +51 -0
  144. package/src/client.ts +749 -0
  145. package/src/css.d.ts +4 -0
  146. package/src/error.ts +120 -0
  147. package/src/index.ts +26 -0
  148. package/src/issuer.ts +1302 -0
  149. package/src/jwt.ts +17 -0
  150. package/src/keys.ts +139 -0
  151. package/src/pkce.ts +40 -0
  152. package/src/provider/apple.ts +127 -0
  153. package/src/provider/arctic.ts +66 -0
  154. package/src/provider/code.ts +227 -0
  155. package/src/provider/cognito.ts +74 -0
  156. package/src/provider/discord.ts +45 -0
  157. package/src/provider/facebook.ts +84 -0
  158. package/src/provider/github.ts +45 -0
  159. package/src/provider/google.ts +85 -0
  160. package/src/provider/index.ts +3 -0
  161. package/src/provider/jumpcloud.ts +45 -0
  162. package/src/provider/keycloak.ts +75 -0
  163. package/src/provider/linkedin.ts +12 -0
  164. package/src/provider/m2m.ts +56 -0
  165. package/src/provider/microsoft.ts +100 -0
  166. package/src/provider/oauth2.ts +297 -0
  167. package/src/provider/oidc.ts +179 -0
  168. package/src/provider/passkey.ts +655 -0
  169. package/src/provider/password.ts +672 -0
  170. package/src/provider/provider.ts +33 -0
  171. package/src/provider/slack.ts +67 -0
  172. package/src/provider/spotify.ts +45 -0
  173. package/src/provider/twitch.ts +45 -0
  174. package/src/provider/x.ts +46 -0
  175. package/src/provider/yahoo.ts +45 -0
  176. package/src/random.ts +24 -0
  177. package/src/storage/aws.ts +59 -0
  178. package/src/storage/cloudflare.ts +77 -0
  179. package/src/storage/dynamo.ts +193 -0
  180. package/src/storage/memory.ts +135 -0
  181. package/src/storage/storage.ts +46 -0
  182. package/src/subject.ts +130 -0
  183. package/src/ui/base.tsx +118 -0
  184. package/src/ui/code.tsx +215 -0
  185. package/src/ui/form.tsx +40 -0
  186. package/src/ui/icon.tsx +95 -0
  187. package/src/ui/passkey.tsx +321 -0
  188. package/src/ui/password.tsx +405 -0
  189. package/src/ui/select.tsx +221 -0
  190. package/src/ui/theme.ts +319 -0
  191. package/src/ui/ui.css +252 -0
  192. package/src/util.ts +58 -0
@@ -0,0 +1,92 @@
1
+ // src/ui/icon.tsx
2
+ import { jsxDEV } from "hono/jsx/jsx-dev-runtime";
3
+ var ICON_GITHUB = /* @__PURE__ */ jsxDEV("svg", {
4
+ viewBox: "0 0 256 250",
5
+ width: "256",
6
+ height: "250",
7
+ fill: "currentColor",
8
+ xmlns: "http://www.w3.org/2000/svg",
9
+ preserveAspectRatio: "xMidYMid",
10
+ children: /* @__PURE__ */ jsxDEV("path", {
11
+ d: "M128.001 0C57.317 0 0 57.307 0 128.001c0 56.554 36.676 104.535 87.535 121.46 6.397 1.185 8.746-2.777 8.746-6.158 0-3.052-.12-13.135-.174-23.83-35.61 7.742-43.124-15.103-43.124-15.103-5.823-14.795-14.213-18.73-14.213-18.73-11.613-7.944.876-7.78.876-7.78 12.853.902 19.621 13.19 19.621 13.19 11.417 19.568 29.945 13.911 37.249 10.64 1.149-8.272 4.466-13.92 8.127-17.116-28.431-3.236-58.318-14.212-58.318-63.258 0-13.975 5-25.394 13.188-34.358-1.329-3.224-5.71-16.242 1.24-33.874 0 0 10.749-3.44 35.21 13.121 10.21-2.836 21.16-4.258 32.038-4.307 10.878.049 21.837 1.47 32.066 4.307 24.431-16.56 35.165-13.12 35.165-13.12 6.967 17.63 2.584 30.65 1.255 33.873 8.207 8.964 13.173 20.383 13.173 34.358 0 49.163-29.944 59.988-58.447 63.157 4.591 3.972 8.682 11.762 8.682 23.704 0 17.126-.148 30.91-.148 35.126 0 3.407 2.304 7.398 8.792 6.14C219.37 232.5 256 184.537 256 128.002 256 57.307 198.691 0 128.001 0Zm-80.06 182.34c-.282.636-1.283.827-2.194.39-.929-.417-1.45-1.284-1.15-1.922.276-.655 1.279-.838 2.205-.399.93.418 1.46 1.293 1.139 1.931Zm6.296 5.618c-.61.566-1.804.303-2.614-.591-.837-.892-.994-2.086-.375-2.66.63-.566 1.787-.301 2.626.591.838.903 1 2.088.363 2.66Zm4.32 7.188c-.785.545-2.067.034-2.86-1.104-.784-1.138-.784-2.503.017-3.05.795-.547 2.058-.055 2.861 1.075.782 1.157.782 2.522-.019 3.08Zm7.304 8.325c-.701.774-2.196.566-3.29-.49-1.119-1.032-1.43-2.496-.726-3.27.71-.776 2.213-.558 3.315.49 1.11 1.03 1.45 2.505.701 3.27Zm9.442 2.81c-.31 1.003-1.75 1.459-3.199 1.033-1.448-.439-2.395-1.613-2.103-2.626.301-1.01 1.747-1.484 3.207-1.028 1.446.436 2.396 1.602 2.095 2.622Zm10.744 1.193c.036 1.055-1.193 1.93-2.715 1.95-1.53.034-2.769-.82-2.786-1.86 0-1.065 1.202-1.932 2.733-1.958 1.522-.03 2.768.818 2.768 1.868Zm10.555-.405c.182 1.03-.875 2.088-2.387 2.37-1.485.271-2.861-.365-3.05-1.386-.184-1.056.893-2.114 2.376-2.387 1.514-.263 2.868.356 3.061 1.403Z"
12
+ }, undefined, false, undefined, this)
13
+ }, undefined, false, undefined, this);
14
+ var ICON_GOOGLE = /* @__PURE__ */ jsxDEV("svg", {
15
+ width: "256",
16
+ height: "262",
17
+ viewBox: "0 0 256 262",
18
+ xmlns: "http://www.w3.org/2000/svg",
19
+ preserveAspectRatio: "xMidYMid",
20
+ children: [
21
+ /* @__PURE__ */ jsxDEV("path", {
22
+ d: "M255.878 133.451c0-10.734-.871-18.567-2.756-26.69H130.55v48.448h71.947c-1.45 12.04-9.283 30.172-26.69 42.356l-.244 1.622 38.755 30.023 2.685.268c24.659-22.774 38.875-56.282 38.875-96.027",
23
+ fill: "#4285F4"
24
+ }, undefined, false, undefined, this),
25
+ /* @__PURE__ */ jsxDEV("path", {
26
+ d: "M130.55 261.1c35.248 0 64.839-11.605 86.453-31.622l-41.196-31.913c-11.024 7.688-25.82 13.055-45.257 13.055-34.523 0-63.824-22.773-74.269-54.25l-1.531.13-40.298 31.187-.527 1.465C35.393 231.798 79.49 261.1 130.55 261.1",
27
+ fill: "#34A853"
28
+ }, undefined, false, undefined, this),
29
+ /* @__PURE__ */ jsxDEV("path", {
30
+ d: "M56.281 156.37c-2.756-8.123-4.351-16.827-4.351-25.82 0-8.994 1.595-17.697 4.206-25.82l-.073-1.73L15.26 71.312l-1.335.635C5.077 89.644 0 109.517 0 130.55s5.077 40.905 13.925 58.602l42.356-32.782",
31
+ fill: "#FBBC05"
32
+ }, undefined, false, undefined, this),
33
+ /* @__PURE__ */ jsxDEV("path", {
34
+ d: "M130.55 50.479c24.514 0 41.05 10.589 50.479 19.438l36.844-35.974C195.245 12.91 165.798 0 130.55 0 79.49 0 35.393 29.301 13.925 71.947l42.211 32.783c10.59-31.477 39.891-54.251 74.414-54.251",
35
+ fill: "#EB4335"
36
+ }, undefined, false, undefined, this)
37
+ ]
38
+ }, undefined, true, undefined, this);
39
+ var ICON_EMAIL = /* @__PURE__ */ jsxDEV("svg", {
40
+ xmlns: "http://www.w3.org/2000/svg",
41
+ fill: "none",
42
+ viewBox: "0 0 24 24",
43
+ "stroke-width": "1.5",
44
+ stroke: "currentColor",
45
+ class: "size-6",
46
+ children: /* @__PURE__ */ jsxDEV("path", {
47
+ "stroke-linecap": "round",
48
+ "stroke-linejoin": "round",
49
+ d: "M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75"
50
+ }, undefined, false, undefined, this)
51
+ }, undefined, false, undefined, this);
52
+ var ICON_SLACK = /* @__PURE__ */ jsxDEV("svg", {
53
+ width: "24",
54
+ height: "24",
55
+ viewBox: "0 0 24 24",
56
+ fill: "none",
57
+ xmlns: "http://www.w3.org/2000/svg",
58
+ children: /* @__PURE__ */ jsxDEV("g", {
59
+ children: [
60
+ /* @__PURE__ */ jsxDEV("path", {
61
+ "fill-rule": "evenodd",
62
+ "clip-rule": "evenodd",
63
+ d: "M8.79948 0C7.47279 0.000978593 6.39909 1.07547 6.40007 2.39951C6.39909 3.72355 7.47377 4.79804 8.80046 4.79902H11.2009V2.40049C11.2018 1.07645 10.1271 0.00195719 8.79948 0ZM8.79948 6.4H2.40039C1.07371 6.40098 -0.000977873 7.47547 2.67973e-06 8.79951C-0.00195842 10.1235 1.07273 11.198 2.39941 11.2H8.79948C10.1262 11.199 11.2009 10.1245 11.1999 8.80049C11.2009 7.47547 10.1262 6.40098 8.79948 6.4Z",
64
+ fill: "currentColor"
65
+ }, undefined, false, undefined, this),
66
+ /* @__PURE__ */ jsxDEV("path", {
67
+ "fill-rule": "evenodd",
68
+ "clip-rule": "evenodd",
69
+ d: "M24.0007 8.79951C24.0016 7.47547 22.9269 6.40098 21.6003 6.4C20.2736 6.40098 19.1989 7.47547 19.1999 8.79951V11.2H21.6003C22.9269 11.199 24.0016 10.1245 24.0007 8.79951ZM17.6006 8.79951V2.39951C17.6016 1.07645 16.5279 0.00195719 15.2012 0C13.8745 0.000978593 12.7998 1.07547 12.8008 2.39951V8.79951C12.7988 10.1235 13.8735 11.198 15.2002 11.2C16.5269 11.199 17.6016 10.1245 17.6006 8.79951Z",
70
+ fill: "currentColor"
71
+ }, undefined, false, undefined, this),
72
+ /* @__PURE__ */ jsxDEV("path", {
73
+ "fill-rule": "evenodd",
74
+ "clip-rule": "evenodd",
75
+ d: "M15.1992 23.9998C16.5259 23.9988 17.6006 22.9243 17.5996 21.6003C17.6006 20.2763 16.5259 19.2018 15.1992 19.2008H12.7988V21.6003C12.7978 22.9234 13.8725 23.9978 15.1992 23.9998ZM15.1992 17.5988H21.5993C22.926 17.5978 24.0007 16.5234 23.9997 15.1993C24.0016 13.8753 22.927 12.8008 21.6003 12.7988H15.2002C13.8735 12.7998 12.7988 13.8743 12.7998 15.1983C12.7988 16.5234 13.8725 17.5978 15.1992 17.5988Z",
76
+ fill: "currentColor"
77
+ }, undefined, false, undefined, this),
78
+ /* @__PURE__ */ jsxDEV("path", {
79
+ "fill-rule": "evenodd",
80
+ "clip-rule": "evenodd",
81
+ d: "M0 15.1993C-0.000979882 16.5234 1.07371 17.5978 2.40039 17.5988C3.72708 17.5978 4.80177 16.5234 4.80079 15.1993V12.7998H2.40039C1.07371 12.8008 -0.000979882 13.8753 0 15.1993ZM6.40007 15.1993V21.5993C6.3981 22.9234 7.47279 23.9978 8.79948 23.9998C10.1262 23.9988 11.2009 22.9243 11.1999 21.6003V15.2013C11.2018 13.8772 10.1271 12.8027 8.80046 12.8008C7.47279 12.8008 6.39909 13.8753 6.40007 15.1993Z",
82
+ fill: "currentColor"
83
+ }, undefined, false, undefined, this)
84
+ ]
85
+ }, undefined, true, undefined, this)
86
+ }, undefined, false, undefined, this);
87
+ export {
88
+ ICON_SLACK,
89
+ ICON_GOOGLE,
90
+ ICON_GITHUB,
91
+ ICON_EMAIL
92
+ };
@@ -0,0 +1,329 @@
1
+ // src/ui/passkey.tsx
2
+ import { Layout } from "./base.js";
3
+ import { FormAlert } from "./form.js";
4
+ import { jsxDEV } from "hono/jsx/jsx-dev-runtime";
5
+ var DEFAULT_COPY = {
6
+ register: "Register",
7
+ register_with_passkey: "Register With Passkey",
8
+ register_other_device: "Use another device",
9
+ register_prompt: "Don't have an account?",
10
+ login_prompt: "Already have an account?",
11
+ login: "Login",
12
+ login_with_passkey: "Login With Passkey",
13
+ change_prompt: "Forgot password?",
14
+ code_resend: "Resend code",
15
+ code_return: "Back to",
16
+ input_email: "Email"
17
+ };
18
+ function PasskeyUI(options) {
19
+ const {
20
+ rpName,
21
+ rpID,
22
+ origin,
23
+ userCanRegisterPasskey,
24
+ authenticatorSelection,
25
+ attestationType,
26
+ timeout
27
+ } = options;
28
+ const copy = {
29
+ ...DEFAULT_COPY,
30
+ ...options.copy
31
+ };
32
+ return {
33
+ authorize: async () => {
34
+ const jsx = /* @__PURE__ */ jsxDEV(Layout, {
35
+ children: [
36
+ /* @__PURE__ */ jsxDEV("script", {
37
+ dangerouslySetInnerHTML: {
38
+ __html: `
39
+
40
+ window.addEventListener("load", async () => {
41
+ const { startAuthentication } = SimpleWebAuthnBrowser;
42
+ const message = document.querySelector("[data-slot='message']");
43
+ const authorizeForm = document.getElementById("authorizeForm");
44
+ const origin = window.location.origin;
45
+ const rpID = window.location.hostname;
46
+ authorizeForm.addEventListener("submit", async (e) => {
47
+ e.preventDefault();
48
+ const formData = new FormData(authorizeForm);
49
+ const email = formData.get("email");
50
+ message.innerHTML = "";
51
+
52
+ // GET registration options from the endpoint that calls
53
+ // @simplewebauthn/server -> generateRegistrationOptions()
54
+ const resp = await fetch(
55
+ "/passkey/authenticate-options?userId=" + email + "&rpID=" + rpID
56
+ );
57
+
58
+ const optionsJSON = await resp.json();
59
+
60
+ if (optionsJSON.error) {
61
+ message.innerHTML = optionsJSON.error;
62
+ return;
63
+ }
64
+
65
+ let attResp;
66
+ try {
67
+ // Pass the options to the authenticator and wait for a response
68
+ attResp = await startAuthentication({ optionsJSON });
69
+ } catch (error) {
70
+ message.innerHTML = error;
71
+ throw error;
72
+ }
73
+ const verificationResp = await fetch(
74
+ "/passkey/authenticate-verify?userId=" +
75
+ email +
76
+ "&rpID=" +
77
+ rpID +
78
+ "&origin=" +
79
+ origin,
80
+ {
81
+ method: "POST",
82
+ headers: {
83
+ "Content-Type": "application/json",
84
+ },
85
+ body: JSON.stringify(attResp),
86
+ }
87
+ );
88
+
89
+ // Check if the request was redirected and the final response is OK
90
+ if (verificationResp.redirected && verificationResp.ok) {
91
+ // Navigate the browser to the final URL
92
+ window.location.href = verificationResp.url;
93
+ } else {
94
+ // Handle errors (e.g., 4xx, 5xx status codes from the final URL)
95
+ console.error(
96
+ "Request failed:",
97
+ verificationResp.status,
98
+ verificationResp.statusText
99
+ );
100
+ try {
101
+ const errorData = await verificationResp.json();
102
+ message.innerHTML = errorData.error;
103
+ } catch (error) {
104
+ message.innerHTML = "Something went wrong";
105
+ }
106
+ }
107
+ });
108
+ });
109
+ `
110
+ }
111
+ }, undefined, false, undefined, this),
112
+ /* @__PURE__ */ jsxDEV("p", {
113
+ children: "Passkeys are a simple and more secure alternative to passwords."
114
+ }, undefined, false, undefined, this),
115
+ /* @__PURE__ */ jsxDEV("p", {
116
+ children: "With passkeys, you can log in with your PIN, biometric sensor, or hardware security key. You can create a passkey on this device, or use another device."
117
+ }, undefined, false, undefined, this),
118
+ /* @__PURE__ */ jsxDEV("form", {
119
+ id: "authorizeForm",
120
+ "data-component": "form",
121
+ method: "post",
122
+ children: [
123
+ /* @__PURE__ */ jsxDEV(FormAlert, {}, undefined, false, undefined, this),
124
+ /* @__PURE__ */ jsxDEV("input", {
125
+ "data-component": "input",
126
+ type: "email",
127
+ name: "email",
128
+ required: true,
129
+ placeholder: copy.input_email
130
+ }, undefined, false, undefined, this),
131
+ /* @__PURE__ */ jsxDEV("button", {
132
+ type: "submit",
133
+ id: "btnLogin",
134
+ "data-component": "button",
135
+ children: copy.login_with_passkey
136
+ }, undefined, false, undefined, this),
137
+ /* @__PURE__ */ jsxDEV("div", {
138
+ "data-component": "form-footer",
139
+ children: /* @__PURE__ */ jsxDEV("span", {
140
+ children: [
141
+ copy.register_prompt,
142
+ " ",
143
+ /* @__PURE__ */ jsxDEV("a", {
144
+ "data-component": "link",
145
+ href: "register",
146
+ children: copy.register
147
+ }, undefined, false, undefined, this)
148
+ ]
149
+ }, undefined, true, undefined, this)
150
+ }, undefined, false, undefined, this)
151
+ ]
152
+ }, undefined, true, undefined, this),
153
+ /* @__PURE__ */ jsxDEV("script", {
154
+ src: "https://unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js"
155
+ }, undefined, false, undefined, this)
156
+ ]
157
+ }, undefined, true, undefined, this);
158
+ return new Response(jsx.toString(), {
159
+ status: 200,
160
+ headers: {
161
+ "Content-Type": "text/html"
162
+ }
163
+ });
164
+ },
165
+ register: async () => {
166
+ const jsx = /* @__PURE__ */ jsxDEV(Layout, {
167
+ children: [
168
+ /* @__PURE__ */ jsxDEV("script", {
169
+ dangerouslySetInnerHTML: {
170
+ __html: `
171
+
172
+ window.addEventListener("load", async () => {
173
+ const { startRegistration } = SimpleWebAuthnBrowser;
174
+ const message = document.querySelector("[data-slot='message']");
175
+ const registerForm = document.getElementById("registerForm");
176
+ const origin = window.location.origin;
177
+ const rpID = window.location.hostname;
178
+ // Start registration when the user clicks a button
179
+ const register = async (otherDevice = false) => {
180
+ const formData = new FormData(registerForm);
181
+ const email = formData.get("email");
182
+ message.innerHTML = "";
183
+
184
+ // GET registration options from the endpoint that calls
185
+ // @simplewebauthn/server -> generateRegistrationOptions()
186
+ const resp = await fetch(
187
+ "/passkey/register-request?userId=" +
188
+ email +
189
+ "&origin=" +
190
+ origin +
191
+ "&rpID=" +
192
+ rpID +
193
+ "&otherDevice=" +
194
+ otherDevice,
195
+ );
196
+ const optionsJSON = await resp.json();
197
+
198
+ if (optionsJSON.error) {
199
+ message.innerHTML = optionsJSON.error;
200
+ return;
201
+ }
202
+
203
+ let attResp;
204
+ try {
205
+ // Pass the options to the authenticator and wait for a response
206
+ attResp = await startRegistration({ optionsJSON });
207
+ } catch (error) {
208
+ message.innerHTML = error;
209
+
210
+ throw error;
211
+ }
212
+
213
+ // POST the response to the endpoint that calls
214
+ // @simplewebauthn/server -> verifyRegistrationResponse()
215
+ try {
216
+ const verificationResp = await fetch(
217
+ "/passkey/register-verify?userId=" +
218
+ email +
219
+ "&origin=" +
220
+ origin +
221
+ "&rpID=" +
222
+ rpID,
223
+ {
224
+ method: "POST",
225
+ headers: {
226
+ "Content-Type": "application/json",
227
+ },
228
+ body: JSON.stringify(attResp),
229
+ }
230
+ );
231
+
232
+ // Check if the request was redirected and the final response is OK
233
+ if (verificationResp.redirected && verificationResp.ok) {
234
+ // Navigate the browser to the final URL
235
+ window.location.href = verificationResp.url;
236
+ } else {
237
+ // Handle errors (e.g., 4xx, 5xx status codes from the final URL)
238
+ console.error(
239
+ "Request failed:",
240
+ verificationResp.status,
241
+ verificationResp.statusText
242
+ );
243
+ try {
244
+ const errorData = await verificationResp.json();
245
+ message.innerHTML = errorData.error;
246
+ } catch (error) {
247
+ message.innerHTML = "Something went wrong";
248
+ }
249
+ }
250
+ } catch (error) {
251
+ console.error(error);
252
+ message.innerHTML = "Something went wrong";
253
+ }
254
+ };
255
+ registerForm.addEventListener("submit", (e) => {
256
+ e.preventDefault();
257
+ register();
258
+ });
259
+
260
+ });
261
+
262
+ `
263
+ }
264
+ }, undefined, false, undefined, this),
265
+ /* @__PURE__ */ jsxDEV("form", {
266
+ id: "registerForm",
267
+ "data-component": "form",
268
+ method: "post",
269
+ children: [
270
+ /* @__PURE__ */ jsxDEV(FormAlert, {}, undefined, false, undefined, this),
271
+ /* @__PURE__ */ jsxDEV("input", {
272
+ "data-component": "input",
273
+ type: "email",
274
+ name: "email",
275
+ required: true,
276
+ placeholder: copy.input_email
277
+ }, undefined, false, undefined, this),
278
+ /* @__PURE__ */ jsxDEV("button", {
279
+ "data-component": "button",
280
+ type: "submit",
281
+ id: "btnRegister",
282
+ children: copy.register_with_passkey
283
+ }, undefined, false, undefined, this),
284
+ /* @__PURE__ */ jsxDEV("button", {
285
+ "data-component": "button",
286
+ type: "submit",
287
+ id: "btnOtherDevice",
288
+ children: copy.register_other_device
289
+ }, undefined, false, undefined, this),
290
+ /* @__PURE__ */ jsxDEV("div", {
291
+ "data-component": "form-footer",
292
+ children: /* @__PURE__ */ jsxDEV("span", {
293
+ children: [
294
+ copy.login_prompt,
295
+ " ",
296
+ /* @__PURE__ */ jsxDEV("a", {
297
+ "data-component": "link",
298
+ href: "authorize",
299
+ children: copy.login
300
+ }, undefined, false, undefined, this)
301
+ ]
302
+ }, undefined, true, undefined, this)
303
+ }, undefined, false, undefined, this)
304
+ ]
305
+ }, undefined, true, undefined, this),
306
+ /* @__PURE__ */ jsxDEV("script", {
307
+ src: "https://unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js"
308
+ }, undefined, false, undefined, this)
309
+ ]
310
+ }, undefined, true, undefined, this);
311
+ return new Response(jsx.toString(), {
312
+ status: 200,
313
+ headers: {
314
+ "Content-Type": "text/html"
315
+ }
316
+ });
317
+ },
318
+ rpName,
319
+ rpID,
320
+ origin,
321
+ userCanRegisterPasskey,
322
+ authenticatorSelection,
323
+ attestationType,
324
+ timeout
325
+ };
326
+ }
327
+ export {
328
+ PasskeyUI
329
+ };