@eventuras/fides-auth-next 0.8.1 → 1.0.0-beta.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.
package/README.md CHANGED
@@ -1,116 +1,195 @@
1
1
  # @eventuras/fides-auth-next
2
2
 
3
- Next.js authentication with XState Store state management.
3
+ Next.js bindings for `@eventuras/fides-auth`. `createFidesAuth` here is the core
4
+ instance bound to `cookies()` from `next/headers`. It caches session reads per
5
+ render with React's `cache()`, and adds a refresh for `proxy.ts`.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
- pnpm add @eventuras/fides-auth-next @xstate/store
10
+ pnpm add @eventuras/fides-auth @eventuras/fides-auth-next
9
11
  ```
10
12
 
11
- ## Quick Start
13
+ `@eventuras/fides-auth`, `next` and `react` are peer dependencies, so the app
14
+ has one copy of core. Needs Node 22.
12
15
 
13
- ```typescript
14
- // 1. Create store
15
- import {
16
- createAuthStore,
17
- createAuthStoreHooks,
18
- } from "@eventuras/fides-auth-next/store";
19
-
20
- export const authStore = createAuthStore({
21
- checkAuthStatus: getAuthStatus,
22
- config: { adminRole: "Admin" },
23
- });
24
-
25
- export const { useAuthStore, useAuthActions } = createAuthStoreHooks(authStore);
26
-
27
- // 2. Initialize in app
28
- useEffect(() => {
29
- initializeAuth(authStore, getAuthStatus);
30
- return startSessionMonitor(authStore, getAuthStatus, { interval: 30_000 });
31
- }, []);
32
-
33
- // 3. Use in components
34
- const { isAuthenticated, user, isAdmin } = useAuthStore();
35
- const { logout } = useAuthActions();
36
- ```
37
-
38
- ## Features
16
+ ## Setup
39
17
 
40
- - **XState Store**: Simple auth state management with automatic session monitoring
41
- - **Cookie Helpers**: Server-side cookie operations
42
- - **Session Management**: High-level session functions
43
- - **OAuth**: Complete OAuth flow with PKCE and RP-initiated logout
44
- - **TypeScript**: Full type safety
45
-
46
- ## Server Setup
47
-
48
- Create one instance and import it where you need it. The library never reads
49
- the environment, so pass the secret in:
18
+ Create one instance in a module of its own and import it where you need it:
50
19
 
51
20
  ```typescript
52
21
  // lib/auth.ts
53
22
  import { createFidesAuth } from "@eventuras/fides-auth-next";
54
23
 
55
24
  export const auth = createFidesAuth({
25
+ oauthConfig: {
26
+ issuer: process.env.OIDC_ISSUER!,
27
+ clientId: process.env.OIDC_CLIENT_ID!,
28
+ clientSecret: process.env.OIDC_CLIENT_SECRET!,
29
+ redirectUri: "https://app.example.com/api/auth/callback",
30
+ scope: "openid profile email offline_access",
31
+ },
56
32
  secret: process.env.SESSION_SECRET!, // openssl rand -hex 32
57
- oauthConfig,
58
33
  });
59
34
  ```
60
35
 
61
- Route handlers:
36
+ The library never reads the environment, so pass the values in. It checks the
37
+ secret and the redirect URI on first use, so `next build` can import the module
38
+ without them. A client with `clientAuth: 'none'` throws at once: the server side
39
+ of an app is a confidential client.
40
+
41
+ | Option | Default | |
42
+ |---|---|---|
43
+ | `sessionStore` | none | Keeps sessions in a store, with only a handle in the cookie. See below. |
44
+ | `storeFields` | none | `(session) => fields`. Plain fields to keep next to each stored session, e.g. your own user id. |
45
+ | `sessionDurationDays` | 30 | How long a session lasts from login. Refreshes don't extend it. |
46
+ | `applicationUrl` | the redirect URI's origin | The app's public origin, for the same-origin check and redirects. |
47
+ | `mapSession` | none | Changes the session built at login, e.g. to add `data`. |
48
+ | `rolesClaim` | `'roles'` | The ID token claim that holds the user's roles, at login and on every refresh that brings an ID token. |
49
+ | `validateReturnTo` | a path on this origin | Turns `?returnTo=` into a safe path, or null. |
50
+ | `defaultRedirectPath` | `'/'` | Where a login without a return path lands. |
51
+ | `postLogoutRedirectUri` | `applicationUrl` | Where the provider sends the user after logout. |
52
+ | `rateLimit` | none | `(request) => boolean`. The handlers answer 429 when it returns false. |
53
+ | `logger` | JSON lines on the console | A `FidesLoggerFactory`. |
54
+ | `onSessionEvent` | none | Gets every session event. See [session events](../fides-auth/docs/session-events.md). |
55
+
56
+ ## Route handlers
62
57
 
63
58
  ```typescript
64
59
  // app/api/auth/login/route.ts
65
60
  export const GET = (request: Request) => auth.handleOidcLogin(request);
66
61
 
67
- // app/api/auth/callback/oidc/route.ts
68
- export const GET = (request: Request) =>
69
- auth.handleOidcCallback(request, { applicationUrl: "https://app.example.com" });
62
+ // app/api/auth/callback/route.ts
63
+ export const GET = (request: Request) => auth.handleOidcCallback(request);
70
64
 
71
65
  // app/api/auth/logout/route.ts
72
- export const POST = (request: Request) =>
73
- auth.handleOidcLogout(request, { postLogoutRedirectUri: "https://app.example.com/" });
66
+ export const POST = (request: Request) => auth.handleOidcLogout(request);
67
+
68
+ // app/api/auth/session/route.ts
69
+ export const GET = (request: Request) => auth.handleSessionInfo(request);
70
+ ```
71
+
72
+ The callback's path must be the redirect URI's. Login takes `?returnTo=/path`
73
+ and lands there with `?login=success`.
74
+
75
+ Logout answers only a `POST` from the app's own pages, so a form does it:
74
76
 
75
- // app/api/auth/heartbeat/route.ts
76
- export const POST = (request: Request) => auth.handleHeartbeat(request);
77
+ ```tsx
78
+ <form method="post" action="/api/auth/logout">
79
+ <button>Log out</button>
80
+ </form>
77
81
  ```
78
82
 
79
- Server components, server actions and route handlers:
83
+ `handleSessionInfo` answers whether there is a session, and whose. It never
84
+ refreshes and never returns tokens. `handleHeartbeat` is there for apps that tie
85
+ refreshes to user activity; it too answers only a same-origin `POST`.
86
+
87
+ ## Reading the session
88
+
89
+ In Server Components, Server Actions and Route Handlers:
80
90
 
81
91
  ```typescript
82
- const session = await auth.getCurrentSession();
83
- const { reason } = await auth.tryGetCurrentSession();
84
- const refreshed = await auth.tryRefreshCurrentSession();
85
- await auth.clearCurrentSession();
92
+ const session = await auth.readSession(); // Session | null
93
+ const { session, reason } = await auth.tryReadSession();
94
+ const tokens = await auth.getTokens(); // Tokens | null
86
95
  ```
87
96
 
88
- API calls with the access token. On a 401, `authorizedFetch` refreshes the
89
- session and retries once; parallel calls in one request share the refresh. The
90
- refresh writes cookies, so it works only in Server Actions and Route Handlers.
91
- In a Server Component pass `refresh: false`, and a 401 is an `http_error`:
97
+ `readSession` and `tryReadSession` share one read per render. A `Session` has
98
+ `user`, `scopes`, `data`, `idp`, `correlationId`, `createdAt` and `expiresAt`.
99
+ The tokens aren't on it: `getTokens` returns them, and `authorizedFetch` uses
100
+ them.
101
+
102
+ `createSession`, `updateSession`, `refreshSession` and `clearSession` write
103
+ cookies, so they work in Server Actions and Route Handlers.
104
+
105
+ ## Keeping the session fresh
106
+
107
+ Nothing refreshes unless you ask, with `refreshSession` or `refreshInProxy`.
108
+ Reads and `authorizedFetch` never do, so they are safe anywhere.
109
+
110
+ A Server Component can't set cookies, so it can't save a refreshed session.
111
+ Refresh in the proxy instead, before the page renders:
92
112
 
93
113
  ```typescript
94
- const api = { allowedBase: "https://api.example.com/v1/" };
114
+ // proxy.ts
115
+ import type { NextRequest } from "next/server";
116
+ import { auth } from "@/lib/auth";
117
+
118
+ export function proxy(request: NextRequest) {
119
+ return auth.refreshInProxy(request);
120
+ }
121
+
122
+ export const config = {
123
+ matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico).*)"],
124
+ };
125
+ ```
126
+
127
+ `refreshInProxy` refreshes a session whose access token expires within 60
128
+ seconds; `ifExpiresWithin` changes that. The window never covers more than half
129
+ the token's lifetime, so a token shorter than the window isn't refreshed on
130
+ every request. It sets the new cookies on the response and on the request it
131
+ forwards, so the page renders with the refreshed session. A request without a
132
+ session cookie passes straight through, and a failed refresh leaves the session
133
+ as it is.
134
+
135
+ The proxy runs for every request a page makes, prefetches included. With cookie
136
+ sessions and a provider that rotates refresh tokens, a request sent before the
137
+ new cookies arrived refreshes with a spent token and fails with
138
+ `invalid_grant`; see
139
+ [Keeping the session fresh](../fides-auth/README.md#keeping-the-session-fresh)
140
+ in the core README. A `sessionStore` avoids it.
95
141
 
96
- // Server Action or Route Handler
97
- const { data } = await auth.authorizedFetch(session, "users/me", {
98
- ...api,
142
+ To send users without a session to the login, check the cookie first:
143
+
144
+ ```typescript
145
+ import { NextResponse, type NextRequest } from "next/server";
146
+
147
+ export function proxy(request: NextRequest) {
148
+ if (!request.cookies.has(auth.cookieNames.session)) {
149
+ return NextResponse.redirect(new URL("/api/auth/login", request.url));
150
+ }
151
+ return auth.refreshInProxy(request);
152
+ }
153
+ ```
154
+
155
+ In a Server Action or Route Handler, refresh first if the access token is about
156
+ to expire. Without `ifExpiresWithin`, `refreshSession` refreshes at once:
157
+
158
+ ```typescript
159
+ await auth.refreshSession({ ifExpiresWithin: 60 });
160
+ ```
161
+
162
+ The result says whether it `refreshed`. On failure it gives a `reason`, and
163
+ `cause: "invalid_grant"` means the user must log in again.
164
+
165
+ ## Calling APIs
166
+
167
+ `authorizedFetch` sends the access token to URLs under `allowedBase`. It never
168
+ refreshes, so it works the same in a Server Component, a Server Action and a
169
+ Route Handler:
170
+
171
+ ```typescript
172
+ const { data } = await auth.authorizedFetch("users/me", {
173
+ allowedBase: "https://api.example.com/v1/",
99
174
  parse: (response) => response.json(),
100
175
  });
101
-
102
- // Server Component
103
- const { data } = await auth.authorizedFetch(session, "users/me", { ...api, refresh: false });
104
176
  ```
105
177
 
106
- The handlers are also exported on their own (`@eventuras/fides-auth-next/oidc-login`
107
- and so on). Those take `oauthConfig` and `secret` in their config.
178
+ A 401 throws an `AuthorizedFetchError` with the reason `http_error`. Pages get
179
+ fresh tokens from `refreshInProxy`; in a Server Action or Route Handler, call
180
+ `refreshSession({ ifExpiresWithin: 60 })` before the request.
181
+
182
+ The error says why, where it can. `accessTokenExpired` is true when the token
183
+ had passed its expiry by the server's clock. `bearerError` is the API's own
184
+ reason from its `WWW-Authenticate` header: `invalid_token` means a refresh may
185
+ help, and `insufficient_scope` means it won't.
108
186
 
109
187
  ## Server sessions
110
188
 
111
- By default the session lives in encrypted cookies. Pass a `sessionStore` to keep
112
- it on the server instead. The browser then holds only a random handle, in the
113
- `session_ref` cookie:
189
+ By default the session lives in the `__Host-session` cookie, in up to three
190
+ chunks. Pass a `sessionStore` to keep it on the server. The browser then holds
191
+ only a random handle, and logout deletes the record.
192
+ [Cookie or store](../fides-auth/README.md#cookie-or-store) compares the two.
114
193
 
115
194
  ```typescript
116
195
  // lib/auth.ts
@@ -122,57 +201,32 @@ const sessionStore: SessionStore = {
122
201
  delete: (key) => db.sessions.remove(key),
123
202
  };
124
203
 
125
- export const auth = createFidesAuth({
126
- secret: process.env.SESSION_SECRET!,
127
- oauthConfig,
128
- sessionStore,
129
- });
204
+ export const auth = createFidesAuth({ oauthConfig, secret, sessionStore });
130
205
  ```
131
206
 
132
- Every handler and helper on `auth` then uses the store, and logout deletes the
133
- record. `secret` is still required: it encrypts the records and seals the login
134
- transaction.
207
+ With a store that implements `findMatching`, `auth.endUserSessions({ sub })`
208
+ ends every session of one user, wherever they are signed in, and revokes their
209
+ refresh tokens.
135
210
 
136
211
  Use a store that every instance shares, such as a database, and add `withLock`
137
212
  when you run more than one instance. `createMemorySessionStore()` from
138
213
  `@eventuras/fides-auth/server` is for tests. See
139
214
  [Server-side sessions](../fides-auth/docs/server-sessions.md) for the store
140
- contract and an adapter example.
215
+ contract.
141
216
 
142
217
  ## Rate limiting
143
218
 
144
- The route handlers use a default limiter. It is deprecated, together with
145
- `globalGETRateLimit`, `globalPOSTRateLimit` and `TokenBucket`: it keys on the raw
146
- `X-Forwarded-For` header, which a client can send itself, and lets requests
147
- without the header through.
148
-
149
- For a limiter of your own, add `@eventuras/fides-auth` and call its handler from
150
- `/server` with the Next cookie store and a `rateLimit` callback. Key it on
151
- something the app trusts, such as the client address your own proxy sets. The
152
- handler answers 429 when the callback returns `false`:
219
+ There is no default limiter. Pass `rateLimit`, keyed on something the app
220
+ trusts, such as the client address your own proxy sets:
153
221
 
154
222
  ```typescript
155
- // app/api/auth/login/route.ts
156
- import { handleOidcLogin } from "@eventuras/fides-auth/server";
157
- import { nextCookieStore } from "@eventuras/fides-auth-next";
158
-
159
- export async function GET(request: Request) {
160
- return handleOidcLogin(request, {
161
- oauthConfig,
162
- secret: process.env.SESSION_SECRET!,
163
- cookies: await nextCookieStore(),
164
- rateLimit: () => limiter.consume(clientKey(request)),
165
- });
166
- }
223
+ export const auth = createFidesAuth({
224
+ oauthConfig,
225
+ secret,
226
+ rateLimit: (request) => limiter.consume(clientKey(request)),
227
+ });
167
228
  ```
168
229
 
169
- `handleOidcCallback`, `handleOidcLogout` and `handleHeartbeat` take the same option.
170
- With a `sessionStore`, also pass those three
171
- `persistence: serverPersistence({ store: sessionStore, secret })`, or they keep
172
- the session in cookies. Build it once. It does not share refreshes with `auth`,
173
- so give the store `withLock`.
174
-
175
- ## Documentation
230
+ ## Upgrading from 0.x
176
231
 
177
- - [Store API](./src/store/) - XState Store details
178
- - [Setup Guide](./SETUP_GUIDE.md) - Complete walkthrough
232
+ See [Upgrading to 1.0](../fides-auth/docs/migrating-to-1.0.md).
package/dist/auth.d.ts CHANGED
@@ -1,76 +1,123 @@
1
1
  /**
2
- * The session helpers and route handlers, bound to one secret and OAuth config.
3
- * No module state: the config lives in the returned object, so a module that
4
- * Next loads more than once behaves the same.
2
+ * createFidesAuth for Next.js. The core instance takes a CookieStore on every
3
+ * call; this one gets it from `cookies()` in next/headers, caches session reads
4
+ * per render, and adds refreshInProxy for `proxy.ts`.
5
5
  */
6
- import { AuthorizedFetchError, type AuthorizedFetchErrorReason, type AuthorizedFetchOptions, type AuthorizedFetchResult, type ClearSessionOptions, type ReadSessionResult, type RefreshSessionResult, type SessionSecret, type SessionStore, type StoredSession } from '@eventuras/fides-auth/server';
7
- import type { OAuthConfig } from '@eventuras/fides-auth/oauth';
8
- import type { CreateSessionOptions, Session } from '@eventuras/fides-auth/types';
9
- import { type OidcCallbackConfig } from './oidc-callback.js';
10
- import { type OidcLoginConfig } from './oidc-login.js';
11
- import { type OidcLogoutConfig } from './oidc-logout.js';
12
- export type { ClearSessionOptions, ReadSessionResult, RefreshSessionResult, SessionSecret };
13
- export type { SessionStore, StoredSession };
14
- export type { AuthorizedFetchErrorReason, AuthorizedFetchOptions, AuthorizedFetchResult };
15
- export { AuthorizedFetchError };
16
- export interface FidesAuthConfig {
17
- /** Session encryption secret, e.g. 64 hex chars. Also seals the login transaction. */
18
- secret: SessionSecret;
19
- /** OAuth/OIDC configuration. */
20
- oauthConfig: OAuthConfig;
6
+ import type { Session, TokenResponse, Tokens } from '@eventuras/fides-auth';
7
+ import type { OidcClient } from '@eventuras/fides-auth/oidc';
8
+ import { type FidesAuthConfig, type FidesAuthorizedFetchOptions, type FidesReadResult, type FidesRefreshResult, type RefreshSessionOptions } from '@eventuras/fides-auth/server';
9
+ import type { SessionClearedTrigger } from '@eventuras/fides-auth/session-events';
10
+ import { type NextRequest, NextResponse } from 'next/server';
11
+ /** Options for {@link FidesAuth.refreshInProxy}. */
12
+ export interface RefreshInProxyOptions {
21
13
  /**
22
- * Keeps sessions in this store, encrypted under `secret`; the cookie holds only a handle.
23
- * Omit to keep them in encrypted cookies.
14
+ * Refresh when the access token expires within this many seconds, or within
15
+ * half its lifetime if that is shorter.
16
+ * @default 60
24
17
  */
25
- sessionStore?: SessionStore;
18
+ ifExpiresWithin?: number;
26
19
  }
27
- /** A handler's config minus what the factory binds. */
28
- type Bound<T> = Omit<T, 'oauthConfig' | 'secret' | 'persistence'>;
29
- export type BoundAuthorizedFetchOptions<T = undefined> = Omit<AuthorizedFetchOptions<T>, 'refresh'> & {
30
- /**
31
- * `false` skips the refresh, so a 401 is an `http_error`. Use it in a Server Component:
32
- * Next won't let it write cookies, and a refresh that can't be saved spends the refresh token.
33
- */
34
- refresh?: false;
35
- };
20
+ /** The core instance's members, bound to the request's cookies. */
36
21
  export interface FidesAuth {
37
- /** The current session, or null. Cached per render; the access token may have expired. */
38
- getCurrentSession(): Promise<Session<any> | null>;
39
- /** The current session, or why there is none. Shares the cache with `getCurrentSession`. */
40
- tryGetCurrentSession(): Promise<ReadSessionResult>;
41
- /** Refreshes the session and saves it. Null on any failure. */
42
- refreshCurrentSession(options?: CreateSessionOptions): Promise<Session | null>;
43
- /** Refreshes the session and, on failure, says why. Prefer it over `refreshCurrentSession`. */
44
- tryRefreshCurrentSession(options?: CreateSessionOptions): Promise<RefreshSessionResult>;
45
- /** Persists a new session. Returns the session cookie's value: the encrypted session, or the handle. */
46
- createAndPersistSession(session: Session): Promise<string>;
47
- /** Deletes the session cookies and, with a `sessionStore`, the record. `trigger` defaults to `logout`. */
48
- clearCurrentSession(options?: ClearSessionOptions): Promise<void>;
22
+ /** `GET`, with an optional `?returnTo=`. Redirects to the provider. */
23
+ handleOidcLogin(request: Request, options?: {
24
+ authorizationParameters?: Record<string, string>;
25
+ }): Promise<Response>;
26
+ /** The provider's redirect back. Starts the session and redirects to the return path. */
27
+ handleOidcCallback(request: Request): Promise<Response>;
49
28
  /**
50
- * `authorizedFetch` that, on a 401, refreshes the session and retries once.
51
- * Parallel calls in one request share one refresh. The refresh writes cookies, so it works
52
- * only in Server Actions and Route Handlers; pass `refresh: false` in a Server Component.
29
+ * `POST`. Ends the session, revokes its refresh token where the provider has
30
+ * a revocation endpoint, and redirects to the provider's end-session endpoint.
53
31
  */
54
- authorizedFetch<T = undefined>(session: Session, url: string | URL, options: BoundAuthorizedFetchOptions<T>): Promise<AuthorizedFetchResult<T>>;
55
- handleOidcLogin(request: Request, options?: Bound<OidcLoginConfig>): Promise<Response>;
56
- handleOidcCallback(request: Request, options: Bound<OidcCallbackConfig>): Promise<Response>;
57
- handleOidcLogout(request: Request, options: Bound<OidcLogoutConfig>): Promise<Response>;
32
+ handleOidcLogout(request: Request, options?: {
33
+ state?: string;
34
+ logoutHint?: string;
35
+ }): Promise<Response>;
36
+ /** `POST`. Refreshes the session. 401 means it is over; 503 means the provider or the store failed. */
58
37
  handleHeartbeat(request: Request): Promise<Response>;
38
+ /** `GET`. Whether there is a session, and whose. Never refreshes, never returns tokens. */
39
+ handleSessionInfo(request: Request): Promise<Response>;
40
+ /** The session, or null. Cached per render. */
41
+ readSession(): Promise<Session | null>;
42
+ /** The session, or why there is none. Cached per render, together with `readSession`. */
43
+ tryReadSession(): Promise<FidesReadResult>;
44
+ /** The session's tokens, or null without a session. The access token may have expired. */
45
+ getTokens(): Promise<Tokens | null>;
46
+ /**
47
+ * Refreshes the tokens, or with `ifExpiresWithin` only when the access token
48
+ * is about to expire. With cookie sessions this writes cookies, so it works
49
+ * only in Server Actions and Route Handlers; pages get theirs from
50
+ * `refreshInProxy`.
51
+ */
52
+ refreshSession(options?: RefreshSessionOptions): Promise<FidesRefreshResult>;
53
+ /** Starts a session from a token response, for a login that doesn't go through the handlers. */
54
+ createSession(tokens: TokenResponse): Promise<Session>;
55
+ /** Changes the user or data. Null when there is no session. */
56
+ updateSession(update: (session: Session) => Session | Promise<Session>): Promise<Session | null>;
57
+ /**
58
+ * Ends the session and revokes its refresh token where the provider has a
59
+ * revocation endpoint. With a store, the record is deleted too. `trigger`
60
+ * defaults to `'logout'`.
61
+ */
62
+ clearSession(options?: {
63
+ trigger?: SessionClearedTrigger;
64
+ }): Promise<void>;
65
+ /**
66
+ * Ends every session of one user, wherever they are signed in, and revokes
67
+ * their refresh tokens. `sub` is the provider's, from the ID token. Needs a
68
+ * `sessionStore` with `findMatching`.
69
+ *
70
+ * @returns How many sessions it ended.
71
+ */
72
+ endUserSessions(user: {
73
+ sub: string;
74
+ iss?: string;
75
+ }, options?: {
76
+ trigger?: SessionClearedTrigger;
77
+ }): Promise<number>;
78
+ /**
79
+ * Calls an API with the session's access token. It never refreshes, so it is
80
+ * safe in a Server Component; a 401 is an `http_error`.
81
+ */
82
+ authorizedFetch<T = undefined>(url: string | URL, options: FidesAuthorizedFetchOptions<T>): Promise<{
83
+ response: Response;
84
+ data: T;
85
+ }>;
86
+ /**
87
+ * For `proxy.ts`. Refreshes a session whose access token expires within
88
+ * `ifExpiresWithin` seconds, or within half its lifetime if that is shorter,
89
+ * before the page renders, since a Server Component can't save a refresh.
90
+ * Sets the new cookies on the response and on the request it forwards, so
91
+ * the page reads the refreshed session.
92
+ *
93
+ * A failed refresh leaves the session as it is. The next API call or
94
+ * heartbeat shows a session that is over; ending it here could undo a refresh
95
+ * that another instance completed with the same refresh token.
96
+ */
97
+ refreshInProxy(request: NextRequest, options?: RefreshInProxyOptions): Promise<NextResponse>;
98
+ /** The session cookie's name, for a proxy that checks whether one is present. */
99
+ readonly cookieNames: {
100
+ session: string;
101
+ };
102
+ /** The instance's OIDC client, for protocol calls it doesn't wrap. */
103
+ readonly oidc: OidcClient;
59
104
  }
60
105
  /**
61
- * Creates the app's auth helpers. Call it once and import the result.
106
+ * Creates the app's auth instance. Call it once, in a module of its own, and
107
+ * import the result. It reads nothing from the environment: pass the secret and
108
+ * the provider config in.
62
109
  *
63
110
  * @example
64
111
  * ```ts
65
112
  * // lib/auth.ts
66
- * export const auth = createFidesAuth({ secret: process.env.SESSION_SECRET!, oauthConfig });
113
+ * export const auth = createFidesAuth({ oauthConfig, secret: process.env.SESSION_SECRET! });
67
114
  *
68
115
  * // app/api/auth/login/route.ts
69
116
  * export const GET = (request: Request) => auth.handleOidcLogin(request);
70
117
  *
71
- * // A server component
72
- * const session = await auth.getCurrentSession();
118
+ * // A Server Component
119
+ * const session = await auth.readSession();
73
120
  * ```
74
121
  */
75
- export declare function createFidesAuth({ secret, oauthConfig, sessionStore }: FidesAuthConfig): FidesAuth;
122
+ export declare function createFidesAuth(config: FidesAuthConfig): FidesAuth;
76
123
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,oBAAoB,EAOpB,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAEzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,OA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