@fluixi/oauth2 1.0.0-alpha.1 → 1.0.0-alpha.100

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 (68) hide show
  1. package/LICENSE +1 -1
  2. package/dist/backchannel.cjs +462 -0
  3. package/dist/backchannel.d.ts +39 -0
  4. package/dist/backchannel.d.ts.map +1 -0
  5. package/dist/backchannel.js +97 -0
  6. package/dist/backchannel.mjs +307 -0
  7. package/dist/{browser-ONMHX3Z3.mjs → browser-TV25RBLT.mjs} +2 -2
  8. package/dist/browser.cjs +10 -3
  9. package/dist/browser.mjs +10 -3
  10. package/dist/callback.cjs +8 -7
  11. package/dist/callback.js +1 -1
  12. package/dist/callback.mjs +3 -2
  13. package/dist/{chunk-4NSOGPLM.mjs → chunk-2B3I72DV.mjs} +1 -1
  14. package/dist/chunk-KOP5Z4LB.mjs +108 -0
  15. package/dist/{chunk-25WE6UWI.mjs → chunk-KTGVSZE6.mjs} +1 -1
  16. package/dist/discovery.cjs +6 -1
  17. package/dist/discovery.d.ts.map +1 -1
  18. package/dist/discovery.js +6 -1
  19. package/dist/discovery.mjs +6 -1
  20. package/dist/dpop-O3HWR7AH.mjs +22 -0
  21. package/dist/{dpop-LVPWWADA.mjs → dpop-SGWG3K2I.mjs} +26 -6
  22. package/dist/{dpop-NS7NKOWM.mjs → dpop-YPGCGL7S.mjs} +22 -2
  23. package/dist/dpop-store.cjs +4 -2
  24. package/dist/dpop-store.mjs +4 -2
  25. package/dist/dpop.cjs +22 -2
  26. package/dist/dpop.d.ts +18 -1
  27. package/dist/dpop.d.ts.map +1 -1
  28. package/dist/dpop.js +23 -2
  29. package/dist/dpop.mjs +22 -2
  30. package/dist/index.cjs +135 -10
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -0
  34. package/dist/index.mjs +138 -13
  35. package/dist/module.cjs +44 -0
  36. package/dist/module.d.ts +13 -0
  37. package/dist/module.d.ts.map +1 -0
  38. package/dist/module.js +22 -0
  39. package/dist/module.mjs +23 -0
  40. package/dist/server.cjs +755 -80
  41. package/dist/server.d.ts +91 -4
  42. package/dist/server.d.ts.map +1 -1
  43. package/dist/server.js +518 -65
  44. package/dist/server.mjs +638 -82
  45. package/dist/service-client.cjs +7 -2
  46. package/dist/service-client.mjs +9 -4
  47. package/dist/service.cjs +116 -7
  48. package/dist/service.d.ts +2 -18
  49. package/dist/service.d.ts.map +1 -1
  50. package/dist/service.js +48 -5
  51. package/dist/service.mjs +116 -7
  52. package/dist/session-monitor.cjs +98 -0
  53. package/dist/session-monitor.d.ts +32 -0
  54. package/dist/session-monitor.d.ts.map +1 -0
  55. package/dist/session-monitor.js +104 -0
  56. package/dist/session-monitor.mjs +77 -0
  57. package/dist/tokens.cjs +1 -1
  58. package/dist/tokens.d.ts +2 -2
  59. package/dist/tokens.d.ts.map +1 -1
  60. package/dist/tokens.js +1 -1
  61. package/dist/tokens.mjs +1 -1
  62. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  63. package/dist/types.d.ts +12 -2
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js +0 -12
  66. package/dist/verify.cjs +30 -4
  67. package/dist/verify.mjs +12 -7
  68. package/package.json +22 -16
package/dist/server.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type ClientAuthMethodInput } from './client-auth.js';
2
+ import { type LogoutStore } from './backchannel.js';
2
3
  import { type Endpoints } from './types.js';
4
+ import { type AppModule } from '@fluixi/start/app';
3
5
  export interface OAuthRoutesConfig {
4
6
  issuer?: string;
5
7
  endpoints?: Endpoints;
@@ -17,6 +19,12 @@ export interface OAuthRoutesConfig {
17
19
  secureCookie?: boolean;
18
20
  /** Where to send the browser after a login with no recorded destination. */
19
21
  defaultReturnTo?: string;
22
+ /**
23
+ * Where back-channel logouts are kept, between the route that hears them and the requests
24
+ * that end their sessions. Default: this process's memory, right for one instance; several
25
+ * instances share one (see `LogoutStore`).
26
+ */
27
+ logouts?: LogoutStore;
20
28
  /**
21
29
  * Origins a login may return to besides this server's own.
22
30
  *
@@ -50,15 +58,61 @@ export interface OAuthRoutesConfig {
50
58
  * short. `0` disables it and asks every time.
51
59
  */
52
60
  userCacheMs?: number;
61
+ /**
62
+ * How long a token request may take, in milliseconds, before it is abandoned. Default
63
+ * 10 000. A renewal abandoned this way may have been processed, so its refresh token is not
64
+ * sent again and the session ends; the provider's own session usually signs the person back
65
+ * in without a prompt.
66
+ */
67
+ tokenTimeoutMs?: number;
53
68
  /** Map the provider's userinfo onto the app's own shape. */
54
69
  mapUser?: (claims: Record<string, unknown>, accessToken: string) => unknown;
70
+ /**
71
+ * Bind tokens to a key with DPoP (RFC 9449), which a provider may require: an Okta org
72
+ * that mandates it refuses a server-mode client without it.
73
+ *
74
+ * The key is made per session at the code exchange and kept in the encrypted session
75
+ * cookie, since a refresh token is bound to the key that obtained it and a refresh with
76
+ * another key is refused. Needs `jose`.
77
+ */
78
+ dpop?: boolean;
79
+ /** Default `ES256`. Must be in the provider's `dpop_signing_alg_values_supported`. */
80
+ dpopAlgorithm?: string;
81
+ /**
82
+ * What a page request from a signed-out visitor does.
83
+ *
84
+ * - `manual` (default): the page renders signed out and offers a way to sign in.
85
+ * - `silent`: the visitor is sent to the provider with `prompt=none`. Someone already
86
+ * signed in there comes back signed in without a click; anyone else comes straight back
87
+ * and the page renders signed out, and is not asked again for `silentRecheck` seconds.
88
+ * Single sign-on without forcing a sign-in on a public page.
89
+ * - `required`: the visitor is sent to sign in. For an app with nothing to show to a
90
+ * stranger, an admin console say.
91
+ *
92
+ * Only page loads are redirected (a GET for a document), never an API or asset request.
93
+ */
94
+ signIn?: 'manual' | 'silent' | 'required';
95
+ /**
96
+ * How long `silent` takes a "nobody signed in" answer as current, in seconds. Default 60.
97
+ * Someone who signs in at the provider afterwards (in another app, another tab) is picked
98
+ * up on their first page load after it. Longer saves round trips for anonymous visitors.
99
+ */
100
+ silentRecheck?: number;
101
+ /** Paths `silent` and `required` leave alone, besides the auth routes: `/health`, `/legal`. */
102
+ publicPaths?: string[];
103
+ /**
104
+ * Paths that always need someone signed in, whatever `signIn` says for the rest: a public
105
+ * site with a private area (`/o` for a workspace) sends a signed-out page load there to
106
+ * sign in, and shows the other pages as `signIn` decides.
107
+ */
108
+ protectedPaths?: string[];
55
109
  }
56
110
  /**
57
- * The middleware.
58
- *
59
- * Handles `<basePath>/login`, `/callback`, `/refresh`, `/me` and `/logout`, and passes
60
- * anything else along untouched.
111
+ * A request carrying the session's access token: the `DPoP` scheme and a proof bound to the
112
+ * token when the provider bound it, `Bearer` otherwise.
61
113
  */
114
+ /** `fetch`, as the signed-in user. What `locals.auth.fetch` is. */
115
+ export type AuthorizedFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
62
116
  export declare function oauthRoutes(config: OAuthRoutesConfig): (request: Request, next: () => Promise<Response>) => Promise<Response>;
63
117
  /**
64
118
  * Put the signed-in user on the request, so a server render knows who is looking.
@@ -86,4 +140,37 @@ export declare function oauthRoutes(config: OAuthRoutesConfig): (request: Reques
86
140
  * having its session resolved first.
87
141
  */
88
142
  export declare function sessionLocals(config: OAuthRoutesConfig): (request: Request, next: () => Promise<Response>) => Promise<Response>;
143
+ /** What `sessionLocals` leaves on a request: the user, and a `fetch` that calls as them. */
144
+ export interface ServerAuth<U = unknown> {
145
+ user: U | null;
146
+ session: {
147
+ expiresAt?: number;
148
+ } | null;
149
+ /** Absent when nobody is signed in. */
150
+ fetch?: AuthorizedFetch;
151
+ /**
152
+ * The visitor has a session but the provider could not be reached to confirm it: tell them
153
+ * it is down, rather than asking them to sign in again.
154
+ */
155
+ unreachable?: boolean;
156
+ }
157
+ /**
158
+ * The request's auth, for server code: a route's data loader, a server function, an API route.
159
+ * Reads the current request's locals, or `request`'s when one is given.
160
+ *
161
+ * ```ts
162
+ * const { fetch } = await requestAuth();
163
+ * const projects = await fetch?.(`${apiUrl}/projects`).then((r) => r.json());
164
+ * ```
165
+ */
166
+ export declare function requestAuth<U = unknown>(request?: Request): Promise<ServerAuth<U>>;
167
+ /**
168
+ * The server half of `authModule`, listed in `src/app.config.server.ts`: the routes and the
169
+ * session middleware that `tokens: 'server'` needs, in the order they have to run.
170
+ *
171
+ * `oauthRoutes` first, so a request to the login route is answered rather than having its
172
+ * session resolved on the way past.
173
+ */
174
+ export declare function authServerModule(config: OAuthRoutesConfig): AppModule;
175
+ export { memoryLogouts, type LogoutEntry, type LogoutStore } from './backchannel.js';
89
176
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAgCA,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yFAAyF;IACzF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,6DAA6D;IAC7D,K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