@_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,54 @@
1
+ // src/util.ts
2
+ function getRelativeUrl(ctx, path) {
3
+ const result = new URL(path, ctx.req.url);
4
+ result.host = ctx.req.header("x-forwarded-host") || result.host;
5
+ result.protocol = ctx.req.header("x-forwarded-proto") || result.protocol;
6
+ result.port = ctx.req.header("x-forwarded-port") || result.port;
7
+ return result.toString();
8
+ }
9
+ var twoPartTlds = [
10
+ "co.uk",
11
+ "co.jp",
12
+ "co.kr",
13
+ "co.nz",
14
+ "co.za",
15
+ "co.in",
16
+ "com.au",
17
+ "com.br",
18
+ "com.cn",
19
+ "com.mx",
20
+ "com.tw",
21
+ "net.au",
22
+ "org.uk",
23
+ "ne.jp",
24
+ "ac.uk",
25
+ "gov.uk",
26
+ "edu.au",
27
+ "gov.au"
28
+ ];
29
+ function isDomainMatch(a, b) {
30
+ if (a === b)
31
+ return true;
32
+ const partsA = a.split(".");
33
+ const partsB = b.split(".");
34
+ const hasTwoPartTld = twoPartTlds.some((tld) => a.endsWith("." + tld) || b.endsWith("." + tld));
35
+ const numParts = hasTwoPartTld ? -3 : -2;
36
+ const min = Math.min(partsA.length, partsB.length, numParts);
37
+ const tailA = partsA.slice(min).join(".");
38
+ const tailB = partsB.slice(min).join(".");
39
+ return tailA === tailB;
40
+ }
41
+ function lazy(fn) {
42
+ let value;
43
+ return () => {
44
+ if (value === undefined) {
45
+ value = fn();
46
+ }
47
+ return value;
48
+ };
49
+ }
50
+ export {
51
+ lazy,
52
+ isDomainMatch,
53
+ getRelativeUrl
54
+ };
@@ -0,0 +1,466 @@
1
+ import { SubjectSchema } from "./subject.js";
2
+ import type { v1 } from "@standard-schema/spec";
3
+ import { InvalidAccessTokenError, InvalidAuthorizationCodeError, InvalidRefreshTokenError } from "./error.js";
4
+ /**
5
+ * The well-known information for an OAuth 2.0 authorization server.
6
+ * @internal
7
+ */
8
+ export interface WellKnown {
9
+ /**
10
+ * The URI to the JWKS endpoint.
11
+ */
12
+ jwks_uri: string;
13
+ /**
14
+ * The URI to the token endpoint.
15
+ */
16
+ token_endpoint: string;
17
+ /**
18
+ * The URI to the authorization endpoint.
19
+ */
20
+ authorization_endpoint: string;
21
+ }
22
+ /**
23
+ * The tokens returned by the auth server.
24
+ */
25
+ export interface Tokens {
26
+ /**
27
+ * The access token.
28
+ */
29
+ access: string;
30
+ /**
31
+ * The refresh token.
32
+ */
33
+ refresh: string;
34
+ /**
35
+ * The number of seconds until the access token expires.
36
+ */
37
+ expiresIn: number;
38
+ }
39
+ interface ResponseLike {
40
+ json(): Promise<unknown>;
41
+ ok: Response["ok"];
42
+ }
43
+ type FetchLike = (...args: any[]) => Promise<ResponseLike>;
44
+ /**
45
+ * The challenge that you can use to verify the code.
46
+ */
47
+ export type Challenge = {
48
+ /**
49
+ * The state that was sent to the redirect URI.
50
+ */
51
+ state: string;
52
+ /**
53
+ * The verifier that was sent to the redirect URI.
54
+ */
55
+ verifier?: string;
56
+ };
57
+ /**
58
+ * Configure the client.
59
+ */
60
+ export interface ClientInput {
61
+ /**
62
+ * The client ID. This is just a string to identify your app.
63
+ *
64
+ * If you have a web app and a mobile app, you want to use different client IDs both.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * {
69
+ * clientID: "my-client"
70
+ * }
71
+ * ```
72
+ */
73
+ clientID: string;
74
+ /**
75
+ * The URL of your OpenAuth server.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * {
80
+ * issuer: "https://auth.myserver.com"
81
+ * }
82
+ * ```
83
+ */
84
+ issuer?: string;
85
+ /**
86
+ * Optionally, override the internally used fetch function.
87
+ *
88
+ * This is useful if you are using a polyfilled fetch function in your application and you
89
+ * want the client to use it too.
90
+ */
91
+ fetch?: FetchLike;
92
+ }
93
+ export interface AuthorizeOptions {
94
+ /**
95
+ * Enable the PKCE flow. This is for SPA apps.
96
+ *
97
+ * ```ts
98
+ * {
99
+ * pkce: true
100
+ * }
101
+ * ```
102
+ *
103
+ * @default false
104
+ */
105
+ pkce?: boolean;
106
+ /**
107
+ * The provider you want to use for the OAuth flow.
108
+ *
109
+ * ```ts
110
+ * {
111
+ * provider: "google"
112
+ * }
113
+ * ```
114
+ *
115
+ * If no provider is specified, the user is directed to a page where they can select from the
116
+ * list of configured providers.
117
+ *
118
+ * If there's only one provider configured, the user will be redirected to that.
119
+ */
120
+ provider?: string;
121
+ }
122
+ export interface AuthorizeResult {
123
+ /**
124
+ * The challenge that you can use to verify the code. This is for the PKCE flow for SPA apps.
125
+ *
126
+ * This is an object that you _stringify_ and store it in session storage.
127
+ *
128
+ * ```ts
129
+ * sessionStorage.setItem("challenge", JSON.stringify(challenge))
130
+ * ```
131
+ */
132
+ challenge: Challenge;
133
+ /**
134
+ * The URL to redirect the user to. This starts the OAuth flow.
135
+ *
136
+ * For example, for SPA apps.
137
+ *
138
+ * ```ts
139
+ * location.href = url
140
+ * ```
141
+ */
142
+ url: string;
143
+ }
144
+ /**
145
+ * Returned when the exchange is successful.
146
+ */
147
+ export interface ExchangeSuccess {
148
+ /**
149
+ * This is always `false` when the exchange is successful.
150
+ */
151
+ err: false;
152
+ /**
153
+ * The access and refresh tokens.
154
+ */
155
+ tokens: Tokens;
156
+ }
157
+ /**
158
+ * Returned when the exchange fails.
159
+ */
160
+ export interface ExchangeError {
161
+ /**
162
+ * The type of error that occurred. You can handle this by checking the type.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
167
+ *
168
+ * console.log(err instanceof InvalidAuthorizationCodeError)
169
+ *```
170
+ */
171
+ err: InvalidAuthorizationCodeError;
172
+ }
173
+ export interface RefreshOptions {
174
+ /**
175
+ * Optionally, pass in the access token.
176
+ */
177
+ access?: string;
178
+ }
179
+ /**
180
+ * Returned when the refresh is successful.
181
+ */
182
+ export interface RefreshSuccess {
183
+ /**
184
+ * This is always `false` when the refresh is successful.
185
+ */
186
+ err: false;
187
+ /**
188
+ * Returns the refreshed tokens only if they've been refreshed.
189
+ *
190
+ * If they are still valid, this will be `undefined`.
191
+ */
192
+ tokens?: Tokens;
193
+ }
194
+ /**
195
+ * Returned when the refresh fails.
196
+ */
197
+ export interface RefreshError {
198
+ /**
199
+ * The type of error that occurred. You can handle this by checking the type.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
204
+ *
205
+ * console.log(err instanceof InvalidRefreshTokenError)
206
+ *```
207
+ */
208
+ err: InvalidRefreshTokenError | InvalidAccessTokenError;
209
+ }
210
+ export interface VerifyOptions {
211
+ /**
212
+ * Optionally, pass in the refresh token.
213
+ *
214
+ * If passed in, this will automatically refresh the access token if it has expired.
215
+ */
216
+ refresh?: string;
217
+ /**
218
+ * @internal
219
+ */
220
+ issuer?: string;
221
+ /**
222
+ * @internal
223
+ */
224
+ audience?: string;
225
+ /**
226
+ * Optionally, override the internally used fetch function.
227
+ *
228
+ * This is useful if you are using a polyfilled fetch function in your application and you
229
+ * want the client to use it too.
230
+ */
231
+ fetch?: FetchLike;
232
+ }
233
+ export interface VerifyResult<T extends SubjectSchema> {
234
+ /**
235
+ * This is always `undefined` when the verify is successful.
236
+ */
237
+ err?: undefined;
238
+ /**
239
+ * Returns the refreshed tokens only if they’ve been refreshed.
240
+ *
241
+ * If they are still valid, this will be undefined.
242
+ */
243
+ tokens?: Tokens;
244
+ /**
245
+ * @internal
246
+ */
247
+ aud: string;
248
+ /**
249
+ * The decoded subjects from the access token.
250
+ *
251
+ * Has the same shape as the subjects you defined when creating the issuer.
252
+ */
253
+ subject: {
254
+ [type in keyof T]: {
255
+ type: type;
256
+ properties: v1.InferOutput<T[type]>;
257
+ };
258
+ }[keyof T];
259
+ }
260
+ /**
261
+ * Returned when the verify call fails.
262
+ */
263
+ export interface VerifyError {
264
+ /**
265
+ * The type of error that occurred. You can handle this by checking the type.
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
270
+ *
271
+ * console.log(err instanceof InvalidRefreshTokenError)
272
+ *```
273
+ */
274
+ err: InvalidRefreshTokenError | InvalidAccessTokenError;
275
+ }
276
+ /**
277
+ * An instance of the OpenAuth client contains the following methods.
278
+ */
279
+ export interface Client {
280
+ /**
281
+ * Start the autorization flow. For example, in SSR sites.
282
+ *
283
+ * ```ts
284
+ * const { url } = await client.authorize(<redirect_uri>, "code")
285
+ * ```
286
+ *
287
+ * This takes a redirect URI and the type of flow you want to use. The redirect URI is the
288
+ * location where the user will be redirected to after the flow is complete.
289
+ *
290
+ * Supports both the _code_ and _token_ flows. We recommend using the _code_ flow as it's more
291
+ * secure.
292
+ *
293
+ * :::tip
294
+ * This returns a URL to redirect the user to. This starts the OAuth flow.
295
+ * :::
296
+ *
297
+ * This returns a URL to the auth server. You can redirect the user to the URL to start the
298
+ * OAuth flow.
299
+ *
300
+ * For SPA apps, we recommend using the PKCE flow.
301
+ *
302
+ * ```ts {4}
303
+ * const { challenge, url } = await client.authorize(
304
+ * <redirect_uri>,
305
+ * "code",
306
+ * { pkce: true }
307
+ * )
308
+ * ```
309
+ *
310
+ * This returns a redirect URL and a challenge that you need to use later to verify the code.
311
+ */
312
+ authorize(redirectURI: string, response: "code" | "token", opts?: AuthorizeOptions): Promise<AuthorizeResult>;
313
+ /**
314
+ * Exchange the code for access and refresh tokens.
315
+ *
316
+ * ```ts
317
+ * const exchanged = await client.exchange(<code>, <redirect_uri>)
318
+ * ```
319
+ *
320
+ * You call this after the user has been redirected back to your app after the OAuth flow.
321
+ *
322
+ * :::tip
323
+ * For SSR sites, the code is returned in the query parameter.
324
+ * :::
325
+ *
326
+ * So the code comes from the query parameter in the redirect URI. The redirect URI here is
327
+ * the one that you passed in to the `authorize` call when starting the flow.
328
+ *
329
+ * :::tip
330
+ * For SPA sites, the code is returned through the URL hash.
331
+ * :::
332
+ *
333
+ * If you used the PKCE flow for an SPA app, the code is returned as a part of the redirect URL
334
+ * hash.
335
+ *
336
+ * ```ts {4}
337
+ * const exchanged = await client.exchange(
338
+ * <code>,
339
+ * <redirect_uri>,
340
+ * <challenge.verifier>
341
+ * )
342
+ * ```
343
+ *
344
+ * You also need to pass in the previously stored challenge verifier.
345
+ *
346
+ * This method returns the access and refresh tokens. Or if it fails, it returns an error that
347
+ * you can handle depending on the error.
348
+ *
349
+ * ```ts
350
+ * import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
351
+ *
352
+ * if (exchanged.err) {
353
+ * if (exchanged.err instanceof InvalidAuthorizationCodeError) {
354
+ * // handle invalid code error
355
+ * }
356
+ * else {
357
+ * // handle other errors
358
+ * }
359
+ * }
360
+ *
361
+ * const { access, refresh } = exchanged.tokens
362
+ * ```
363
+ */
364
+ exchange(code: string, redirectURI: string, verifier?: string): Promise<ExchangeSuccess | ExchangeError>;
365
+ /**
366
+ * Refreshes the tokens if they have expired. This is used in an SPA app to maintain the
367
+ * session, without logging the user out.
368
+ *
369
+ * ```ts
370
+ * const next = await client.refresh(<refresh_token>)
371
+ * ```
372
+ *
373
+ * Can optionally take the access token as well. If passed in, this will skip the refresh
374
+ * if the access token is still valid.
375
+ *
376
+ * ```ts
377
+ * const next = await client.refresh(<refresh_token>, { access: <access_token> })
378
+ * ```
379
+ *
380
+ * This returns the refreshed tokens only if they've been refreshed.
381
+ *
382
+ * ```ts
383
+ * if (!next.err) {
384
+ * // tokens are still valid
385
+ * }
386
+ * if (next.tokens) {
387
+ * const { access, refresh } = next.tokens
388
+ * }
389
+ * ```
390
+ *
391
+ * Or if it fails, it returns an error that you can handle depending on the error.
392
+ *
393
+ * ```ts
394
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
395
+ *
396
+ * if (next.err) {
397
+ * if (next.err instanceof InvalidRefreshTokenError) {
398
+ * // handle invalid refresh token error
399
+ * }
400
+ * else {
401
+ * // handle other errors
402
+ * }
403
+ * }
404
+ * ```
405
+ */
406
+ refresh(refresh: string, opts?: RefreshOptions): Promise<RefreshSuccess | RefreshError>;
407
+ /**
408
+ * Verify the token in the incoming request.
409
+ *
410
+ * This is typically used for SSR sites where the token is stored in an HTTP only cookie. And
411
+ * is passed to the server on every request.
412
+ *
413
+ * ```ts
414
+ * const verified = await client.verify(<subjects>, <token>)
415
+ * ```
416
+ *
417
+ * This takes the subjects that you had previously defined when creating the issuer.
418
+ *
419
+ * :::tip
420
+ * If the refresh token is passed in, it'll automatically refresh the access token.
421
+ * :::
422
+ *
423
+ * This can optionally take the refresh token as well. If passed in, it'll automatically
424
+ * refresh the access token if it has expired.
425
+ *
426
+ * ```ts
427
+ * const verified = await client.verify(<subjects>, <token>, { refresh: <refresh_token> })
428
+ * ```
429
+ *
430
+ * This returns the decoded subjects from the access token. And the tokens if they've been
431
+ * refreshed.
432
+ *
433
+ * ```ts
434
+ * // based on the subjects you defined earlier
435
+ * console.log(verified.subject.properties.userID)
436
+ *
437
+ * if (verified.tokens) {
438
+ * const { access, refresh } = verified.tokens
439
+ * }
440
+ * ```
441
+ *
442
+ * Or if it fails, it returns an error that you can handle depending on the error.
443
+ *
444
+ * ```ts
445
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
446
+ *
447
+ * if (verified.err) {
448
+ * if (verified.err instanceof InvalidRefreshTokenError) {
449
+ * // handle invalid refresh token error
450
+ * }
451
+ * else {
452
+ * // handle other errors
453
+ * }
454
+ * }
455
+ * ```
456
+ */
457
+ verify<T extends SubjectSchema>(subjects: T, token: string, options?: VerifyOptions): Promise<VerifyResult<T> | VerifyError>;
458
+ }
459
+ /**
460
+ * Create an OpenAuth client.
461
+ *
462
+ * @param input - Configure the client.
463
+ */
464
+ export declare function createClient(input: ClientInput): Client;
465
+ export {};
466
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AA+CA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,wBAAwB,EAEzB,MAAM,YAAY,CAAA;AAGnB;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,YAAY;IACpB,I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QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,GAAG,aAAa,CAAC,CAAA;IAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,OAAO,CACL,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,cAAc,GAAG,YAAY,CAAC,CAAA;IACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACH,MAAM,CAAC,CAAC,SAAS,aAAa,EAC5B,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA;CAC1C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CA0MvD"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * A list of errors that can be thrown by OpenAuth.
3
+ *
4
+ * You can use these errors to check the type of error and handle it. For example.
5
+ *
6
+ * ```ts
7
+ * import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
8
+ *
9
+ * if (err instanceof InvalidAuthorizationCodeError) {
10
+ * // handle invalid code error
11
+ * }
12
+ * ```
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ /**
17
+ * The OAuth server returned an error.
18
+ */
19
+ export declare class OauthError extends Error {
20
+ error: "invalid_request" | "invalid_grant" | "unauthorized_client" | "access_denied" | "unsupported_grant_type" | "server_error" | "temporarily_unavailable";
21
+ description: string;
22
+ constructor(error: "invalid_request" | "invalid_grant" | "unauthorized_client" | "access_denied" | "unsupported_grant_type" | "server_error" | "temporarily_unavailable", description: string);
23
+ }
24
+ /**
25
+ * The `provider` needs to be passed in.
26
+ */
27
+ export declare class MissingProviderError extends OauthError {
28
+ constructor();
29
+ }
30
+ /**
31
+ * The given parameter is missing.
32
+ */
33
+ export declare class MissingParameterError extends OauthError {
34
+ parameter: string;
35
+ constructor(parameter: string);
36
+ }
37
+ /**
38
+ * The given client is not authorized to use the redirect URI that was passed in.
39
+ */
40
+ export declare class UnauthorizedClientError extends OauthError {
41
+ clientID: string;
42
+ constructor(clientID: string, redirectURI: string);
43
+ }
44
+ /**
45
+ * The browser was in an unknown state.
46
+ *
47
+ * This can happen when certain cookies have expired. Or the browser was switched in the middle
48
+ * of the authentication flow.
49
+ */
50
+ export declare class UnknownStateError extends Error {
51
+ constructor();
52
+ }
53
+ /**
54
+ * The given subject is invalid.
55
+ */
56
+ export declare class InvalidSubjectError extends Error {
57
+ constructor();
58
+ }
59
+ /**
60
+ * The given refresh token is invalid.
61
+ */
62
+ export declare class InvalidRefreshTokenError extends Error {
63
+ constructor();
64
+ }
65
+ /**
66
+ * The given access token is invalid.
67
+ */
68
+ export declare class InvalidAccessTokenError extends Error {
69
+ constructor();
70
+ }
71
+ /**
72
+ * The given authorization code is invalid.
73
+ */
74
+ export declare class InvalidAuthorizationCodeError extends Error {
75
+ constructor();
76
+ }
77
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAE1B,KAAK,EACR,iBAAiB,GACjB,eAAe,GACf,qBAAqB,GACrB,eAAe,GACf,wBAAwB,GACxB,cAAc,GACd,yBAAyB;IACtB,WAAW,EAAE,MAAM;gBARnB,KAAK,EACR,iBAAiB,GACjB,eAAe,GACf,qBAAqB,GACrB,eAAe,GACf,wBAAwB,GACxB,cAAc,GACd,yBAAyB,EACtB,WAAW,EAAE,MAAM;CAI7B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;;CAOnD;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,UAAU;IAChC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAGrC;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IAE5C,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM;CAOtB;AAED;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;;CAM3C;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;;CAI7C;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;;CAIlD;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;;CAIjD;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;;CAIvD"}
@@ -0,0 +1,20 @@
1
+ export {
2
+ /**
3
+ * @deprecated
4
+ * Use `import { createClient } from "@openauthjs/openauth/client"` instead - it will tree shake better
5
+ */
6
+ createClient, } from "./client.js";
7
+ export {
8
+ /**
9
+ * @deprecated
10
+ * Use `import { createSubjects } from "@openauthjs/openauth/subject"` instead - it will tree shake better
11
+ */
12
+ createSubjects, } from "./subject.js";
13
+ import { issuer } from "./issuer.js";
14
+ export {
15
+ /**
16
+ * @deprecated
17
+ * Use `import { issuer } from "@openauthjs/openauth"` instead, it was renamed
18
+ */
19
+ issuer as authorizer, issuer, };
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACL;;;GAGG;AACH,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO;AACL;;;GAGG;AACH,cAAc,GACf,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO;AACL;;;GAGG;AACH,MAAM,IAAI,UAAU,EACpB,MAAM,GACP,CAAA"}