@mherod/get-cookie 4.4.2 → 4.5.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 (59) hide show
  1. package/README.md +26 -5
  2. package/dist/bun.cjs +77 -0
  3. package/dist/bun.cjs.map +1 -0
  4. package/dist/bun.d.cts +3 -0
  5. package/dist/bun.d.ts +3 -0
  6. package/dist/bun.js +77 -0
  7. package/dist/bun.js.map +1 -0
  8. package/dist/cli.cjs +14 -11
  9. package/dist/cli.cjs.map +1 -1
  10. package/dist/index.cjs +11 -11
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +103 -37
  13. package/dist/index.d.ts +103 -37
  14. package/dist/index.js +11 -11
  15. package/dist/index.js.map +1 -1
  16. package/dist/node.cjs +77 -0
  17. package/dist/node.cjs.map +1 -0
  18. package/dist/node.d.cts +3 -0
  19. package/dist/node.d.ts +3 -0
  20. package/dist/node.js +77 -0
  21. package/dist/node.js.map +1 -0
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +32 -14
  24. package/.claude/settings.local.json +0 -3
  25. package/.dependency-cruiser.js +0 -277
  26. package/.env.example +0 -5
  27. package/.husky/commit-msg +0 -19
  28. package/.husky/pre-commit +0 -29
  29. package/.husky/pre-push +0 -21
  30. package/.idea/codeStyles/Project.xml +0 -59
  31. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  32. package/.idea/get-cookie.iml +0 -13
  33. package/.idea/git_toolbox_prj.xml +0 -15
  34. package/.idea/jsLibraryMappings.xml +0 -6
  35. package/.idea/modules.xml +0 -8
  36. package/.idea/prettier.xml +0 -9
  37. package/.idea/runConfigurations/build.xml +0 -12
  38. package/.idea/vcs.xml +0 -6
  39. package/.nvmrc +0 -1
  40. package/biome.json +0 -117
  41. package/commitlint.config.js +0 -12
  42. package/eslint.config.js +0 -255
  43. package/examples/README.md +0 -71
  44. package/examples/advanced-usage.ts +0 -56
  45. package/examples/auth-tokens.ts +0 -143
  46. package/examples/basic-usage.ts +0 -43
  47. package/examples/cli-examples.sh +0 -51
  48. package/examples/comprehensive-demo.ts +0 -202
  49. package/examples/curl-integration.sh +0 -311
  50. package/examples/features-demo.sh +0 -260
  51. package/examples/github-auth.sh +0 -295
  52. package/examples/quick-start.sh +0 -115
  53. package/jest.setup.js +0 -34
  54. package/tsconfig.build.json +0 -9
  55. package/tsconfig.cli.json +0 -16
  56. package/tsconfig.tsup.json +0 -12
  57. package/tsup.cli.ts +0 -59
  58. package/tsup.lib.ts +0 -46
  59. package/typedoc.json +0 -17
@@ -1,51 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Set up the get-cookie function to use the source directly
4
- get-cookie() {
5
- pnpm tsx src/cli/cli.ts "$@"
6
- }
7
-
8
- # Note: Ensure all browser instances are closed before running these examples
9
- # On macOS, grant "Full Disk Access" to your terminal
10
-
11
- echo "GitHub Cookie Examples:"
12
- echo "----------------------"
13
-
14
- # Get GitHub authentication cookies (useful for API requests)
15
- echo "\nGetting GitHub authentication cookies:"
16
- echo "These cookies are needed for authenticated API requests"
17
- get-cookie user_session github.com --render
18
- get-cookie __Host-user_session_same_site github.com --render
19
-
20
- # Get GitHub user preferences
21
- echo "\nGetting GitHub user preferences:"
22
- echo "These cookies store user-specific settings"
23
- get-cookie color_mode github.com --render
24
- echo "Color mode preferences (light/dark theme settings)"
25
- get-cookie tz github.com --render
26
- echo "Timezone setting"
27
-
28
- # Get GitHub session state
29
- echo "\nGetting GitHub session state:"
30
- echo "These cookies indicate login status and user identity"
31
- get-cookie logged_in github.com --render
32
- echo "Login status"
33
- get-cookie dotcom_user github.com --render
34
- echo "GitHub username"
35
-
36
- # Get all GitHub cookies in grouped format
37
- echo "\nGetting all GitHub cookies (grouped by browser):"
38
- echo "Useful for debugging authentication issues"
39
- get-cookie % github.com --dump-grouped
40
-
41
- # Different output formats for automation
42
- echo "\nOutput format examples:"
43
- echo "----------------------"
44
-
45
- # JSON output (useful for scripting)
46
- echo "\nJSON format (good for scripting):"
47
- get-cookie user_session github.com --output json
48
-
49
- # Rendered output (human-readable)
50
- echo "\nRendered format (good for debugging):"
51
- get-cookie user_session github.com --render
@@ -1,202 +0,0 @@
1
- #!/usr/bin/env tsx
2
- /**
3
- * Comprehensive demonstration of get-cookie library features
4
- * This example shows various ways to query and work with browser cookies
5
- */
6
-
7
- import { getCookie } from "../src";
8
- import { CookieStrategyFactory } from "../src/cli/services/CookieStrategyFactory";
9
-
10
- async function demonstrateFeatures() {
11
- console.log("🍪 Get-Cookie Library Demonstration\n");
12
- console.log("=".repeat(50));
13
-
14
- // 1. Basic cookie retrieval
15
- console.log("\n📌 Example 1: Get specific cookies by name");
16
- console.log("-".repeat(40));
17
- try {
18
- const githubSession = await getCookie({
19
- name: "user_session",
20
- domain: "github.com",
21
- });
22
-
23
- if (githubSession.length > 0) {
24
- console.log(
25
- `Found ${githubSession.length} GitHub user_session cookie(s):`,
26
- );
27
- githubSession.forEach((cookie, i) => {
28
- console.log(
29
- ` ${i + 1}. Browser: ${cookie.meta?.browser || "Unknown"}`,
30
- );
31
- console.log(
32
- ` Profile: ${cookie.meta?.file?.split("/").slice(-2, -1)[0] || "Default"}`,
33
- );
34
- console.log(` Expires: ${cookie.expiry}`);
35
- console.log(` Decrypted: ${cookie.meta?.decrypted || "N/A"}`);
36
- });
37
- } else {
38
- console.log("No GitHub user_session cookies found");
39
- }
40
- } catch (error) {
41
- console.error("Error retrieving cookies:", error);
42
- }
43
-
44
- // 2. Wildcard search
45
- console.log("\n📌 Example 2: Wildcard search for all cookies");
46
- console.log("-".repeat(40));
47
- try {
48
- const allGoogleCookies = await getCookie({
49
- name: "%", // Wildcard for any name
50
- domain: "google.com",
51
- });
52
-
53
- if (allGoogleCookies.length > 0) {
54
- // Group by cookie name
55
- const cookieNames = [...new Set(allGoogleCookies.map((c) => c.name))];
56
- console.log(`Found ${allGoogleCookies.length} Google cookies:`);
57
- console.log(`Unique cookie names (${cookieNames.length}):`);
58
- cookieNames.slice(0, 10).forEach((name) => {
59
- const count = allGoogleCookies.filter((c) => c.name === name).length;
60
- console.log(` - ${name} (${count} instance${count > 1 ? "s" : ""})`);
61
- });
62
- if (cookieNames.length > 10) {
63
- console.log(` ... and ${cookieNames.length - 10} more`);
64
- }
65
- } else {
66
- console.log("No Google cookies found");
67
- }
68
- } catch (error) {
69
- console.error("Error retrieving cookies:", error);
70
- }
71
-
72
- // 3. Browser-specific queries
73
- console.log("\n📌 Example 3: Browser-specific strategies");
74
- console.log("-".repeat(40));
75
-
76
- const browsers = ["chrome", "firefox", "safari"];
77
- for (const browser of browsers) {
78
- try {
79
- const strategy = CookieStrategyFactory.createStrategy(browser);
80
- const cookies = await strategy.queryCookies("%", "github.com");
81
-
82
- if (cookies.length > 0) {
83
- console.log(
84
- `✓ ${browser.toUpperCase()}: Found ${cookies.length} GitHub cookies`,
85
- );
86
- } else {
87
- console.log(
88
- `✗ ${browser.toUpperCase()}: No GitHub cookies or browser not available`,
89
- );
90
- }
91
- } catch (_error) {
92
- console.log(`✗ ${browser.toUpperCase()}: Not available on this system`);
93
- }
94
- }
95
-
96
- // 4. Composite strategy (all browsers)
97
- console.log("\n📌 Example 4: Composite strategy (query all browsers)");
98
- console.log("-".repeat(40));
99
- try {
100
- const compositeStrategy = CookieStrategyFactory.createStrategy();
101
- const allCookies = await compositeStrategy.queryCookies("%", "github.com");
102
-
103
- // Group by browser
104
- const browserGroups = allCookies.reduce(
105
- (acc, cookie) => {
106
- const browser = cookie.meta?.browser || "Unknown";
107
- if (!acc[browser]) {
108
- acc[browser] = [];
109
- }
110
- acc[browser].push(cookie);
111
- return acc;
112
- },
113
- {} as Record<string, typeof allCookies>,
114
- );
115
-
116
- console.log("Cookies found across all browsers:");
117
- Object.entries(browserGroups).forEach(([browser, cookies]) => {
118
- const uniqueNames = [...new Set(cookies.map((c) => c.name))];
119
- console.log(
120
- ` ${browser}: ${cookies.length} cookies (${uniqueNames.length} unique names)`,
121
- );
122
- });
123
- } catch (error) {
124
- console.error("Error with composite strategy:", error);
125
- }
126
-
127
- // 5. Session vs Persistent cookies
128
- console.log("\n📌 Example 5: Session vs Persistent cookies");
129
- console.log("-".repeat(40));
130
- try {
131
- const allCookies = await getCookie({
132
- name: "%",
133
- domain: "google.com",
134
- });
135
-
136
- const sessionCookies = allCookies.filter(
137
- (c) =>
138
- c.expiry === "Infinity" || c.expiry === undefined || c.expiry === null,
139
- );
140
- const persistentCookies = allCookies.filter(
141
- (c) => c.expiry && c.expiry !== "Infinity",
142
- );
143
-
144
- console.log(`Session cookies: ${sessionCookies.length}`);
145
- console.log(`Persistent cookies: ${persistentCookies.length}`);
146
-
147
- if (persistentCookies.length > 0) {
148
- // Find the cookie expiring soonest
149
- const cookiesWithDates = persistentCookies.filter(
150
- (c): c is typeof c & { expiry: Date } => c.expiry instanceof Date,
151
- );
152
- const soonest = cookiesWithDates.sort((a, b) => {
153
- const dateA = a.expiry.getTime();
154
- const dateB = b.expiry.getTime();
155
- return dateA - dateB;
156
- })[0];
157
-
158
- if (soonest) {
159
- const daysUntilExpiry = Math.ceil(
160
- (soonest.expiry.getTime() - Date.now()) / (1000 * 60 * 60 * 24),
161
- );
162
- console.log(
163
- `Cookie expiring soonest: ${soonest.name} (${daysUntilExpiry} days)`,
164
- );
165
- }
166
- }
167
- } catch (error) {
168
- console.error("Error analyzing cookies:", error);
169
- }
170
-
171
- // 6. Performance measurement
172
- console.log("\n📌 Example 6: Performance measurement");
173
- console.log("-".repeat(40));
174
-
175
- const iterations = 5;
176
- const times: number[] = [];
177
-
178
- for (let i = 0; i < iterations; i++) {
179
- const start = Date.now();
180
- await getCookie({
181
- name: "%",
182
- domain: "github.com",
183
- });
184
- const elapsed = Date.now() - start;
185
- times.push(elapsed);
186
- }
187
-
188
- const avgTime = times.reduce((a, b) => a + b, 0) / times.length;
189
- const minTime = Math.min(...times);
190
- const maxTime = Math.max(...times);
191
-
192
- console.log(`Query performance (${iterations} iterations):`);
193
- console.log(` Average: ${avgTime.toFixed(2)}ms`);
194
- console.log(` Min: ${minTime}ms`);
195
- console.log(` Max: ${maxTime}ms`);
196
-
197
- console.log(`\n${"=".repeat(50)}`);
198
- console.log("✅ Demonstration complete!");
199
- }
200
-
201
- // Run the demonstration
202
- demonstrateFeatures().catch(console.error);
@@ -1,311 +0,0 @@
1
- #!/bin/bash
2
-
3
- # ============================================================================
4
- # get-cookie + curl Integration Guide
5
- # ============================================================================
6
- # Comprehensive guide for using get-cookie with curl for authenticated
7
- # HTTP requests. This covers all common patterns from basic to advanced.
8
- # ============================================================================
9
-
10
- # Colors for output
11
- RED='\033[0;31m'
12
- GREEN='\033[0;32m'
13
- YELLOW='\033[1;33m'
14
- BLUE='\033[0;34m'
15
- NC='\033[0m' # No Color
16
-
17
- echo -e "${BLUE}🍪 get-cookie + curl Integration Guide${NC}"
18
- echo "================================================"
19
- echo ""
20
-
21
- # ============================================================================
22
- # Example 1: Basic Single Cookie with curl
23
- # ============================================================================
24
- echo -e "${YELLOW}1️⃣ Basic Single Cookie Extraction${NC}"
25
- echo "─────────────────────────────────────"
26
-
27
- echo -e "${GREEN}Extracting GitHub session cookie...${NC}"
28
- USER_SESSION=$(get-cookie user_session github.com --render 2>/dev/null | head -1)
29
-
30
- if [ -n "$USER_SESSION" ]; then
31
- echo -e "${GREEN}✓ Found GitHub session cookie${NC}"
32
- echo " Value: ${USER_SESSION:0:30}... (truncated for security)"
33
-
34
- # Test with curl
35
- echo -e "\n${GREEN}Testing with GitHub API...${NC}"
36
- RESPONSE=$(curl -s \
37
- -H "Cookie: $USER_SESSION" \
38
- -H "User-Agent: get-cookie-demo" \
39
- "https://api.github.com/user")
40
-
41
- LOGIN=$(echo "$RESPONSE" | jq -r '.login // empty' 2>/dev/null)
42
- if [ -n "$LOGIN" ]; then
43
- echo -e "${GREEN}✓ Authenticated as: @$LOGIN${NC}"
44
- else
45
- echo -e "${YELLOW}⚠ API may not accept browser cookies (use tokens for API)${NC}"
46
- fi
47
- else
48
- echo -e "${RED}✗ No GitHub session cookie found${NC}"
49
- echo " Make sure you're logged into GitHub in your browser"
50
- fi
51
- echo ""
52
-
53
- # ============================================================================
54
- # Example 2: The Perfect Pattern - Using --url flag
55
- # ============================================================================
56
- echo -e "${YELLOW}2️⃣ The Perfect Pattern: --url flag${NC}"
57
- echo "─────────────────────────────────────────────"
58
-
59
- echo -e "${GREEN}The --url flag automatically gets all cookies for a URL:${NC}"
60
- echo ""
61
- echo -e "${BLUE}curl -H \"Cookie: \$(get-cookie --url <URL> --render)\" <URL>${NC}"
62
- echo ""
63
-
64
- # Reusable function for authenticated requests
65
- authenticated_curl() {
66
- local url=$1
67
- shift # Remove first argument, pass the rest to curl
68
-
69
- # Get cookies for this specific URL
70
- local cookies=$(get-cookie --url "$url" --render 2>/dev/null)
71
-
72
- if [ -n "$cookies" ]; then
73
- curl -H "Cookie: $cookies" "$@" "$url"
74
- else
75
- echo "No cookies found for $url" >&2
76
- curl "$@" "$url"
77
- fi
78
- }
79
-
80
- echo -e "${GREEN}Reusable function for authenticated requests:${NC}"
81
- cat << 'EOF'
82
- authenticated_curl() {
83
- local url=$1
84
- shift
85
- curl -H "Cookie: $(get-cookie --url "$url" --render 2>/dev/null)" "$@" "$url"
86
- }
87
-
88
- # Usage:
89
- # authenticated_curl https://github.com/settings/profile -s | grep username
90
- # authenticated_curl https://example.com/file.pdf -o file.pdf
91
- EOF
92
- echo ""
93
-
94
- # Test the function
95
- echo -e "${GREEN}Testing authenticated_curl function:${NC}"
96
- HTTP_CODE=$(authenticated_curl "https://github.com/settings/profile" -s -o /dev/null -w "%{http_code}" 2>/dev/null)
97
- if [ "$HTTP_CODE" = "200" ]; then
98
- echo -e "${GREEN}✓ Successfully accessed protected page (HTTP 200)${NC}"
99
- elif [ "$HTTP_CODE" = "302" ]; then
100
- echo -e "${YELLOW}⚠ Redirected to login (HTTP 302)${NC}"
101
- else
102
- echo -e "${BLUE}ℹ HTTP $HTTP_CODE${NC}"
103
- fi
104
- echo ""
105
-
106
- # ============================================================================
107
- # Example 3: Multiple Cookies for Complex Authentication
108
- # ============================================================================
109
- echo -e "${YELLOW}3️⃣ Multiple Cookie Authentication${NC}"
110
- echo "───────────────────────────────────────"
111
-
112
- echo -e "${GREEN}Extracting all GitHub cookies...${NC}"
113
- COOKIES_JSON=$(get-cookie % github.com --output json 2>/dev/null)
114
-
115
- if [ -n "$COOKIES_JSON" ]; then
116
- COOKIE_COUNT=$(echo "$COOKIES_JSON" | jq 'length')
117
- echo -e "${GREEN}✓ Found $COOKIE_COUNT GitHub cookies${NC}"
118
-
119
- # Build cookie header with multiple cookies
120
- COOKIE_HEADER=$(echo "$COOKIES_JSON" | jq -r '.[] | "\(.name)=\(.value)"' | paste -sd '; ')
121
-
122
- if [ -n "$COOKIE_HEADER" ]; then
123
- echo -e "\n${GREEN}Testing with multiple cookies...${NC}"
124
- STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
125
- -H "Cookie: $COOKIE_HEADER" \
126
- -H "User-Agent: get-cookie-demo" \
127
- "https://github.com/settings/profile")
128
-
129
- if [ "$STATUS" = "200" ]; then
130
- echo -e "${GREEN}✓ Successfully accessed protected page (HTTP $STATUS)${NC}"
131
- else
132
- echo -e "${RED}✗ Access denied (HTTP $STATUS)${NC}"
133
- fi
134
- fi
135
- else
136
- echo -e "${RED}✗ Failed to extract cookies${NC}"
137
- fi
138
- echo ""
139
-
140
- # ============================================================================
141
- # Example 4: Download Protected Content
142
- # ============================================================================
143
- echo -e "${YELLOW}4️⃣ Download Protected Content${NC}"
144
- echo "───────────────────────────────────"
145
-
146
- echo -e "${GREEN}Example: Download a file that requires authentication${NC}"
147
- echo ""
148
- echo -e "${BLUE}curl -H \"Cookie: \$(get-cookie --url <URL> --render)\" \\"
149
- echo " -H \"User-Agent: YourApp\" \\"
150
- echo " -o file.pdf \\"
151
- echo " https://example.com/protected/file.pdf${NC}"
152
- echo ""
153
-
154
- # ============================================================================
155
- # Example 5: POST Request with Authentication
156
- # ============================================================================
157
- echo -e "${YELLOW}5️⃣ POST Request with Authentication${NC}"
158
- echo "─────────────────────────────────────────"
159
-
160
- echo -e "${GREEN}Example: Creating a GitHub gist with authentication${NC}"
161
- echo ""
162
- cat << 'EOF'
163
- curl -X POST \
164
- -H "Cookie: $(get-cookie --url https://api.github.com/gists --render)" \
165
- -H "Content-Type: application/json" \
166
- -H "User-Agent: get-cookie-demo" \
167
- -d '{
168
- "description": "Created via get-cookie + curl",
169
- "public": false,
170
- "files": {
171
- "test.md": {
172
- "content": "# Hello from get-cookie!"
173
- }
174
- }
175
- }' \
176
- https://api.github.com/gists
177
- EOF
178
- echo ""
179
-
180
- # ============================================================================
181
- # Example 6: Cookie Validation Function
182
- # ============================================================================
183
- echo -e "${YELLOW}6️⃣ Cookie Validation${NC}"
184
- echo "───────────────────────"
185
-
186
- validate_cookie() {
187
- local domain=$1
188
- local cookie_name=$2
189
-
190
- echo -e "${GREEN}Validating $cookie_name for $domain...${NC}"
191
-
192
- # Get cookie with metadata
193
- COOKIE_JSON=$(get-cookie "$cookie_name" "$domain" --output json 2>/dev/null)
194
-
195
- if [ -n "$COOKIE_JSON" ] && [ "$COOKIE_JSON" != "[]" ]; then
196
- # Parse cookie details
197
- EXPIRY=$(echo "$COOKIE_JSON" | jq -r '.[0].expiry' 2>/dev/null)
198
- BROWSER=$(echo "$COOKIE_JSON" | jq -r '.[0].meta.browser' 2>/dev/null)
199
- DECRYPTED=$(echo "$COOKIE_JSON" | jq -r '.[0].meta.decrypted' 2>/dev/null)
200
-
201
- echo " ✓ Cookie found"
202
- echo " Browser: $BROWSER"
203
- echo " Decrypted: $DECRYPTED"
204
-
205
- # Check if expired
206
- if [ "$EXPIRY" != "null" ] && [ "$EXPIRY" != "Infinity" ]; then
207
- EXPIRY_TIMESTAMP=$(date -d "$EXPIRY" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "${EXPIRY%%.*}" +%s 2>/dev/null)
208
- CURRENT_TIMESTAMP=$(date +%s)
209
-
210
- if [ -n "$EXPIRY_TIMESTAMP" ]; then
211
- if [ "$EXPIRY_TIMESTAMP" -gt "$CURRENT_TIMESTAMP" ]; then
212
- DAYS_LEFT=$(( ($EXPIRY_TIMESTAMP - $CURRENT_TIMESTAMP) / 86400 ))
213
- echo " Valid for: $DAYS_LEFT days"
214
- else
215
- echo -e " ${RED}⚠ EXPIRED${NC}"
216
- fi
217
- else
218
- echo " Expiry: $EXPIRY"
219
- fi
220
- else
221
- echo " Type: Session cookie"
222
- fi
223
- return 0
224
- else
225
- echo -e " ${RED}✗ Cookie not found${NC}"
226
- return 1
227
- fi
228
- }
229
-
230
- # Validate some common cookies
231
- validate_cookie "github.com" "user_session"
232
- echo ""
233
-
234
- # ============================================================================
235
- # Example 7: Reusable Shell Function for Multiple Cookies
236
- # ============================================================================
237
- echo -e "${YELLOW}7️⃣ Reusable Function for Multiple Cookies${NC}"
238
- echo "───────────────────────────────────────────────"
239
-
240
- cat << 'EOF'
241
- get_cookie_for_curl() {
242
- local cookie_name=$1
243
- local domain=$2
244
- local cookie_value=$(get-cookie "$cookie_name" "$domain" --render 2>/dev/null | head -1)
245
-
246
- if [ -n "$cookie_value" ]; then
247
- echo "$cookie_value"
248
- return 0
249
- else
250
- echo ""
251
- return 1
252
- fi
253
- }
254
-
255
- # Build a cookie header with multiple specific cookies
256
- COOKIE_HEADER=""
257
- for cookie in "user_session" "dotcom_user" "_gh_sess"; do
258
- if cookie_value=$(get_cookie_for_curl "$cookie" "github.com"); then
259
- if [ -n "$COOKIE_HEADER" ]; then
260
- COOKIE_HEADER="$COOKIE_HEADER; $cookie_value"
261
- else
262
- COOKIE_HEADER="$cookie_value"
263
- fi
264
- fi
265
- done
266
-
267
- curl -H "Cookie: $COOKIE_HEADER" https://github.com/settings/profile
268
- EOF
269
- echo ""
270
-
271
- # ============================================================================
272
- # Example 8: Using with Other Tools
273
- # ============================================================================
274
- echo -e "${YELLOW}8️⃣ Using with Other HTTP Tools${NC}"
275
- echo "─────────────────────────────────────"
276
-
277
- echo -e "${GREEN}With wget:${NC}"
278
- echo -e "${BLUE}wget --header=\"Cookie: \$(get-cookie --url <URL> --render)\" <URL>${NC}"
279
- echo ""
280
-
281
- echo -e "${GREEN}With HTTPie:${NC}"
282
- echo -e "${BLUE}http GET <URL> Cookie:\"\$(get-cookie --url <URL> --render)\"${NC}"
283
- echo ""
284
-
285
- echo -e "${GREEN}With jq for JSON APIs:${NC}"
286
- echo -e "${BLUE}curl -H \"Cookie: \$(get-cookie --url <URL> --render)\" <URL> | jq .${NC}"
287
- echo ""
288
-
289
- # ============================================================================
290
- # Tips and Best Practices
291
- # ============================================================================
292
- echo -e "${BLUE}📚 Tips and Best Practices${NC}"
293
- echo "================================================"
294
- echo ""
295
- echo "1. ${YELLOW}Security:${NC} Never log or save cookie values in scripts"
296
- echo "2. ${YELLOW}Expiration:${NC} Check cookie expiry before using them"
297
- echo "3. ${YELLOW}User-Agent:${NC} Always set a User-Agent header with curl"
298
- echo "4. ${YELLOW}CSRF Tokens:${NC} Some APIs require CSRF tokens in addition to session cookies"
299
- echo "5. ${YELLOW}Rate Limiting:${NC} Respect API rate limits when using automation"
300
- echo ""
301
- echo -e "${GREEN}Example one-liner to test authentication:${NC}"
302
- echo -e "${BLUE}get-cookie --url <URL> --render | xargs -I {} curl -s -H \"Cookie: {}\" <URL> | jq .login${NC}"
303
- echo ""
304
- echo -e "${GREEN}Example to save cookies to a file:${NC}"
305
- echo -e "${BLUE}get-cookie % domain.com --output json > cookies.json${NC}"
306
- echo ""
307
- echo -e "${GREEN}Example to use with wget instead of curl:${NC}"
308
- echo -e "${BLUE}wget --header=\"Cookie: \$(get-cookie --url <URL> --render)\" <URL>${NC}"
309
- echo ""
310
-
311
- echo -e "${GREEN}✅ Integration guide complete!${NC}"