@tidecloak/nextjs 0.13.9 → 0.13.13

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.
@@ -0,0 +1,128 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ /**
3
+ * Token exchange configuration for hybrid mode
4
+ */
5
+ export interface TokenExchangeConfig {
6
+ /** TideCloak server URL (e.g., "https://auth.example.com") */
7
+ authServerUrl: string;
8
+ /** TideCloak realm name */
9
+ realm: string;
10
+ /** Client ID registered in TideCloak */
11
+ clientId: string;
12
+ /** Client secret (for confidential clients) */
13
+ clientSecret?: string;
14
+ }
15
+ /**
16
+ * Token response from TideCloak
17
+ */
18
+ export interface TokenResponse {
19
+ access_token: string;
20
+ refresh_token?: string;
21
+ id_token?: string;
22
+ expires_in: number;
23
+ refresh_expires_in?: number;
24
+ token_type: string;
25
+ scope?: string;
26
+ }
27
+ /**
28
+ * Authorization code data sent from the client
29
+ */
30
+ export interface AuthCodeData {
31
+ code: string;
32
+ code_verifier: string;
33
+ redirect_uri: string;
34
+ }
35
+ /**
36
+ * Exchange an authorization code for tokens.
37
+ * Use this in your Next.js API route to complete the hybrid mode flow.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // app/api/auth/callback/route.ts
42
+ * import { exchangeCodeForTokens } from '@tidecloak/nextjs/server';
43
+ *
44
+ * export async function POST(req: NextRequest) {
45
+ * const body = await req.json();
46
+ * const authData = JSON.parse(body.accessToken);
47
+ *
48
+ * const result = await exchangeCodeForTokens({
49
+ * authServerUrl: process.env.TIDECLOAK_URL!,
50
+ * realm: process.env.TIDECLOAK_REALM!,
51
+ * clientId: process.env.TIDECLOAK_CLIENT_ID!,
52
+ * }, authData);
53
+ *
54
+ * if (!result.success) {
55
+ * return NextResponse.json({ error: result.error }, { status: 401 });
56
+ * }
57
+ *
58
+ * // Store tokens server-side and create session
59
+ * return NextResponse.json({ success: true });
60
+ * }
61
+ * ```
62
+ */
63
+ export declare function exchangeCodeForTokens(config: TokenExchangeConfig, authData: AuthCodeData): Promise<{
64
+ success: true;
65
+ tokens: TokenResponse;
66
+ } | {
67
+ success: false;
68
+ error: string;
69
+ }>;
70
+ /**
71
+ * Refresh an access token using a refresh token.
72
+ * Use this to get a new access token when the current one expires.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const result = await refreshAccessToken({
77
+ * authServerUrl: process.env.TIDECLOAK_URL!,
78
+ * realm: process.env.TIDECLOAK_REALM!,
79
+ * clientId: process.env.TIDECLOAK_CLIENT_ID!,
80
+ * }, session.tokens.refresh_token);
81
+ *
82
+ * if (result.success) {
83
+ * // Update stored tokens
84
+ * session.tokens = result.tokens;
85
+ * }
86
+ * ```
87
+ */
88
+ export declare function refreshAccessToken(config: TokenExchangeConfig, refreshToken: string): Promise<{
89
+ success: true;
90
+ tokens: TokenResponse;
91
+ } | {
92
+ success: false;
93
+ error: string;
94
+ }>;
95
+ /**
96
+ * Parse the auth data from the client request body.
97
+ * The client sends the authorization code data as a JSON string in accessToken field.
98
+ */
99
+ export declare function parseAuthCodeData(requestBody: {
100
+ accessToken?: string;
101
+ }): AuthCodeData | null;
102
+ /**
103
+ * Create a session cookie response helper.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const response = NextResponse.json({ success: true });
108
+ * setSessionCookie(response, sessionId, { maxAge: 86400 });
109
+ * return response;
110
+ * ```
111
+ */
112
+ export declare function setSessionCookie(response: NextResponse, sessionId: string, options?: {
113
+ name?: string;
114
+ maxAge?: number;
115
+ path?: string;
116
+ secure?: boolean;
117
+ sameSite?: 'strict' | 'lax' | 'none';
118
+ httpOnly?: boolean;
119
+ }): void;
120
+ /**
121
+ * Get session ID from request cookies
122
+ */
123
+ export declare function getSessionFromRequest(req: NextRequest, cookieName?: string): string | null;
124
+ /**
125
+ * Clear session cookie
126
+ */
127
+ export declare function clearSessionCookie(response: NextResponse, cookieName?: string): void;
128
+ //# sourceMappingURL=tokenExchange.d.ts.map
@@ -0,0 +1 @@
1
+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MAAM,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BvF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,GAAG,IAAI,CAgB5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAA;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACd,GACL,IAAI,CAiBN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,UAAU,GAAE,MAAkB,GAC7B,MAAM,GAAG,IAAI,CAEf;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,EACtB,UAAU,GAAE,MAAkB,GAC7B,IAAI,CAEN"}
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@tidecloak/nextjs",
3
- "version": "0.13.9",
3
+ "version": "0.13.13",
4
4
  "description": "TideCloak nextjs SDK",
5
5
  "exports": {
6
6
  ".": {
7
- "import": "./dist/esm/index.js",
8
7
  "types": "./dist/types/index.d.ts",
9
- "require": "./dist/cjs/index.js"
8
+ "import": "./dist/esm/index.js",
9
+ "require": "./dist/cjs/index.js",
10
+ "default": "./dist/esm/index.js"
10
11
  },
11
12
  "./server": {
12
- "import": "./dist/esm/server/index.js",
13
13
  "types": "./dist/types/server/index.d.ts",
14
- "require": "./dist/cjs/server/index.js"
14
+ "edge-light": "./dist/esm/server/index.js",
15
+ "import": "./dist/esm/server/index.js",
16
+ "require": "./dist/cjs/server/index.js",
17
+ "default": "./dist/esm/server/index.js"
15
18
  }
16
19
  },
17
20
  "files": [
@@ -48,11 +51,13 @@
48
51
  "prepare": "npm run build"
49
52
  },
50
53
  "dependencies": {
51
- "@tidecloak/react": "^0.13.9",
52
- "@tidecloak/verify": "^0.13.9"
54
+ "@tidecloak/react": "^0.13.13",
55
+ "@tidecloak/verify": "^0.13.13"
53
56
  },
54
57
  "devDependencies": {
58
+ "@types/node": "^22.0.0",
55
59
  "@types/react": "^19.1.8",
56
- "@types/react-dom": "^19.1.6"
60
+ "@types/react-dom": "^19.1.6",
61
+ "next": "^15.0.0"
57
62
  }
58
63
  }