@mherod/get-cookie 4.4.1 → 4.4.3

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/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
4
4
  "description": "Node.js module for querying cookies from Chrome, Firefox, and Safari browsers",
5
- "packageManager": "pnpm@9.15.2",
6
5
  "type": "module",
7
6
  "source": "src/index.ts",
8
7
  "bin": {
@@ -25,42 +24,8 @@
25
24
  "publishConfig": {
26
25
  "access": "public"
27
26
  },
28
- "scripts": {
29
- "clean": "rm -rf dist",
30
- "build:lib": "tsup --config tsup.lib.ts",
31
- "build:cli": "tsup --config tsup.cli.ts",
32
- "build": "pnpm run build:lib && pnpm run build:cli",
33
- "test": "jest",
34
- "type-check": "tsc --noEmit --skipLibCheck",
35
- "lint": "biome check --diagnostic-level=error .",
36
- "lint:eslint": "eslint --config eslint.config.js \"src/**/*.{ts,js}\"",
37
- "lint:all": "pnpm run lint && pnpm run lint:eslint",
38
- "lint:fix": "biome check --write --unsafe . && eslint --config eslint.config.js --fix \"src/**/*.{ts,js}\"",
39
- "lint:staged": "biome check --staged --write .",
40
- "format": "biome format --write .",
41
- "format:check": "biome check --diagnostic-level=error .",
42
- "validate": "pnpm run type-check && pnpm run lint && pnpm run test && pnpm run check-links && pnpm run format:check",
43
- "audit": "pnpm audit --audit-level moderate",
44
- "audit:fix": "pnpm audit --fix",
45
- "outdated": "pnpm outdated",
46
- "prepack": "pnpm run validate",
47
- "prepublishOnly": "pnpm run clean && pnpm run validate && pnpm run build",
48
- "dev": "tsc -w -p tsconfig.json & tsc-alias -w -p tsconfig.json",
49
- "read-github": "NODE_OPTIONS=\"-r tsconfig-paths/register\" tsx scripts/read-github-cookies.ts",
50
- "prepare": "husky install",
51
- "docs": "typedoc && ./scripts/fix-typedoc.sh && vitepress build docs",
52
- "docs:dev": "vitepress dev docs",
53
- "docs:preview": "vitepress preview docs",
54
- "check-links": "./scripts/check-vitepress-links.sh",
55
- "deps": "madge --ts-config ./tsconfig.json src/index.ts",
56
- "deps:circular": "madge --circular --ts-config ./tsconfig.json src/",
57
- "deps:orphans": "madge --orphans --ts-config ./tsconfig.json src/",
58
- "deps:text": "depcruise src --include-only \"^src\" --output-type text",
59
- "deps:html": "depcruise src --include-only \"^src\" --output-type html --output-to dependency-report.html",
60
- "deps:validate": "depcruise src --config .dependency-cruiser.js"
61
- },
62
27
  "engines": {
63
- "node": "^20.0.0 || ^22.0.0 || ^24.0.0"
28
+ "node": "^20.0.0 || ^22.0.0 || ^24.0.0 || ^25.0.0"
64
29
  },
65
30
  "keywords": [],
66
31
  "author": "Matthew Herod",
@@ -72,8 +37,8 @@
72
37
  "destr": "^2.0.5",
73
38
  "dotenv": "17.2.3",
74
39
  "fast-glob": "^3.3.3",
75
- "jsonwebtoken": "^9.0.2",
76
- "lodash-es": "^4.17.21",
40
+ "jsonwebtoken": "^9.0.3",
41
+ "lodash-es": "^4.17.23",
77
42
  "minimist": "^1.2.8",
78
43
  "tsconfig-paths": "^4.2.0",
79
44
  "zod": "^4.1.11"
@@ -119,11 +84,6 @@
119
84
  "typescript": "^5.9.2",
120
85
  "vitepress": "^1.6.4"
121
86
  },
122
- "pnpm": {
123
- "overrides": {
124
- "esbuild": "^0.25.0"
125
- }
126
- },
127
87
  "lint-staged": {
128
88
  "*.{js,ts}": [
129
89
  "biome check --write --no-errors-on-unmatched"
@@ -135,5 +95,36 @@
135
95
  "biome format --write --no-errors-on-unmatched",
136
96
  "./scripts/check-vitepress-links.sh"
137
97
  ]
98
+ },
99
+ "scripts": {
100
+ "clean": "rm -rf dist",
101
+ "build:lib": "tsup --config tsup.lib.ts",
102
+ "build:cli": "tsup --config tsup.cli.ts",
103
+ "build": "pnpm run build:lib && pnpm run build:cli",
104
+ "test": "jest",
105
+ "type-check": "tsc --noEmit --skipLibCheck",
106
+ "lint": "biome check --diagnostic-level=error .",
107
+ "lint:eslint": "eslint --config eslint.config.js \"src/**/*.{ts,js}\"",
108
+ "lint:all": "pnpm run lint && pnpm run lint:eslint",
109
+ "lint:fix": "biome check --write --unsafe . && eslint --config eslint.config.js --fix \"src/**/*.{ts,js}\"",
110
+ "lint:staged": "biome check --staged --write .",
111
+ "format": "biome format --write .",
112
+ "format:check": "biome check --diagnostic-level=error .",
113
+ "validate": "pnpm run type-check && pnpm run lint && pnpm run test && pnpm run check-links && pnpm run format:check",
114
+ "audit": "pnpm audit --audit-level moderate",
115
+ "audit:fix": "pnpm audit --fix",
116
+ "outdated": "pnpm outdated",
117
+ "dev": "tsc -w -p tsconfig.json & tsc-alias -w -p tsconfig.json",
118
+ "read-github": "NODE_OPTIONS=\"-r tsconfig-paths/register\" tsx scripts/read-github-cookies.ts",
119
+ "docs": "typedoc && ./scripts/fix-typedoc.sh && vitepress build docs",
120
+ "docs:dev": "vitepress dev docs",
121
+ "docs:preview": "vitepress preview docs",
122
+ "check-links": "./scripts/check-vitepress-links.sh",
123
+ "deps": "madge --ts-config ./tsconfig.json src/index.ts",
124
+ "deps:circular": "madge --circular --ts-config ./tsconfig.json src/",
125
+ "deps:orphans": "madge --orphans --ts-config ./tsconfig.json src/",
126
+ "deps:text": "depcruise src --include-only \"^src\" --output-type text",
127
+ "deps:html": "depcruise src --include-only \"^src\" --output-type html --output-to dependency-report.html",
128
+ "deps:validate": "depcruise src --config .dependency-cruiser.js"
138
129
  }
139
- }
130
+ }
package/tsup.cli.ts CHANGED
@@ -29,6 +29,7 @@ export default defineConfig({
29
29
  bundle: true,
30
30
  tsconfig: "./tsconfig.cli.json",
31
31
  noExternal: ["lodash-es"],
32
+ external: ["bun:sqlite"],
32
33
  treeshake: true,
33
34
  splitting: false,
34
35
  skipNodeModulesBundle: true,
package/tsup.lib.ts CHANGED
@@ -26,7 +26,15 @@ export default defineConfig({
26
26
  platform: "node",
27
27
  bundle: true,
28
28
  tsconfig: "./tsconfig.tsup.json",
29
- external: ["fs", "path", "crypto", "os", "child_process", "lodash-es"],
29
+ external: [
30
+ "fs",
31
+ "path",
32
+ "crypto",
33
+ "os",
34
+ "child_process",
35
+ "lodash-es",
36
+ "bun:sqlite",
37
+ ],
30
38
  treeshake: true,
31
39
  splitting: false,
32
40
  skipNodeModulesBundle: true,
@@ -1,117 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Chrome-specific cookie extraction demo
4
- echo "šŸŖ Chrome Cookie Extraction with get-cookie"
5
- echo "==========================================="
6
- echo ""
7
-
8
- # Basic Chrome cookie extraction
9
- echo "1ļøāƒ£ Basic Chrome cookie extraction:"
10
- echo "─────────────────────────────────"
11
- echo "Command: get-cookie --url https://github.com --browser chrome --render"
12
- echo ""
13
- COOKIES=$(get-cookie --url https://github.com --browser chrome --render 2>/dev/null | head -c 100)
14
- echo "Output (truncated): $COOKIES..."
15
- echo ""
16
-
17
- # JSON output for debugging
18
- echo "2ļøāƒ£ Chrome cookies in JSON format:"
19
- echo "────────────────────────────────"
20
- echo "Command: get-cookie --url https://github.com --browser chrome --output json"
21
- echo ""
22
- get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | jq '.[:2]'
23
- echo ""
24
-
25
- # Filtering duplicates
26
- echo "3ļøāƒ£ Handling duplicate cookies:"
27
- echo "─────────────────────────────"
28
- echo "Chrome may have duplicate cookies from different profiles."
29
- echo ""
30
- echo "Session cookies found:"
31
- get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | \
32
- jq -r '.[] | select(.name == "user_session") | " • \(.value[0:20])... (\(.value | length) chars)"'
33
- echo ""
34
-
35
- # Smart filtering
36
- echo "4ļøāƒ£ Smart cookie filtering (recommended):"
37
- echo "───────────────────────────────────────"
38
- echo "Filter to get the longest (most likely valid) cookie value:"
39
- echo ""
40
- cat << 'EOF'
41
- VALID_SESSION=$(get-cookie --url https://github.com --browser chrome --output json | \
42
- jq -r '.[] | select(.name == "user_session" and (.value | length) > 20) | .value' | \
43
- head -1)
44
- EOF
45
- echo ""
46
-
47
- # Using with curl
48
- echo "5ļøāƒ£ Using Chrome cookies with curl:"
49
- echo "────────────────────────────────"
50
- echo "Simple approach (may fail with duplicates):"
51
- echo 'curl -H "Cookie: $(get-cookie --url <URL> --browser chrome --render)" <URL>'
52
- echo ""
53
- echo "Robust approach (with filtering):"
54
- cat << 'EOF'
55
- # Get deduplicated cookies (longest value wins)
56
- COOKIES=$(get-cookie --url <URL> --browser chrome --output json | \
57
- jq -r 'group_by(.name) | map(max_by(.value | length)) |
58
- .[] | "\(.name)=\(.value)"' | tr '\n' ';')
59
-
60
- curl -H "Cookie: $COOKIES" <URL>
61
- EOF
62
- echo ""
63
-
64
- # Testing authentication
65
- echo "6ļøāƒ£ Testing GitHub authentication with Chrome cookies:"
66
- echo "───────────────────────────────────────────────────"
67
- COOKIES=$(get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | \
68
- jq -r 'group_by(.name) | map(max_by(.value | length)) | .[] | "\(.name)=\(.value)"' | tr '\n' ';')
69
-
70
- echo -n "Testing with deduplicated cookies: "
71
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
72
- -H "Cookie: $COOKIES" \
73
- -H "User-Agent: Mozilla/5.0" \
74
- "https://github.com/settings/profile")
75
-
76
- if [ "$HTTP_CODE" = "200" ]; then
77
- echo "āœ… Success (HTTP 200)"
78
- elif [ "$HTTP_CODE" = "302" ]; then
79
- echo "āŒ Redirected to login (HTTP 302)"
80
- else
81
- echo "āš ļø HTTP $HTTP_CODE"
82
- fi
83
- echo ""
84
-
85
- # Check cookie counts
86
- echo "7ļøāƒ£ Cookie statistics:"
87
- echo "──────────────────"
88
- TOTAL=$(get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | jq 'length')
89
- UNIQUE=$(get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | jq '[.[] | .name] | unique | length')
90
- echo "• Total cookies: $TOTAL"
91
- echo "• Unique cookie names: $UNIQUE"
92
- echo "• Duplicates: $((TOTAL - UNIQUE))"
93
- echo ""
94
-
95
- # Expired cookie filtering
96
- echo "8ļøāƒ£ Expired cookie filtering:"
97
- echo "──────────────────────────"
98
- WITHOUT=$(get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | jq 'length')
99
- WITH=$(get-cookie --url https://github.com --browser chrome --output json --include-expired 2>/dev/null | jq 'length')
100
- echo "• Without --include-expired: $WITHOUT cookies"
101
- echo "• With --include-expired: $WITH cookies"
102
- if [ "$WITH" -gt "$WITHOUT" ]; then
103
- echo "• āœ… Filtered out $((WITH - WITHOUT)) expired cookies"
104
- else
105
- echo "• ā„¹ļø No expired cookies found"
106
- fi
107
- echo ""
108
-
109
- echo "šŸ’” Key Insights:"
110
- echo "──────────────"
111
- echo "• Chrome may store duplicate cookies from different profiles"
112
- echo "• The --render flag outputs all cookies, including duplicates"
113
- echo "• For authentication, deduplicate by taking the longest value"
114
- echo "• Expired cookies are filtered by default (use --include-expired to see all)"
115
- echo "• Use JSON output + jq for precise cookie control"
116
- echo ""
117
- echo "āœ… Chrome cookie extraction complete!"
@@ -1,126 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Chrome Profile Selection Demo
4
- echo "šŸŖ Chrome Profile Selection with get-cookie"
5
- echo "==========================================="
6
- echo ""
7
- echo "The new --profile option allows targeting specific Chrome profiles by name."
8
- echo ""
9
-
10
- # List available Chrome profiles
11
- echo "šŸ“‹ Available Chrome Profiles:"
12
- echo "──────────────────────────"
13
- if [ -f ~/Library/Application\ Support/Google/Chrome/Local\ State ]; then
14
- cat ~/Library/Application\ Support/Google/Chrome/Local\ State | \
15
- jq -r '.profile.info_cache | to_entries | .[] | " • \(.value.name) (directory: \(.key))"'
16
- else
17
- echo " Chrome Local State file not found"
18
- fi
19
- echo ""
20
-
21
- # Demonstrate profile-specific extraction
22
- echo "šŸŽÆ Profile-Specific Cookie Extraction:"
23
- echo "────────────────────────────────────"
24
- echo ""
25
-
26
- echo "1ļøāƒ£ Extract from a specific profile by name:"
27
- echo " Command: get-cookie --url https://github.com --browser chrome --profile \"plugg.in\" --render"
28
- echo ""
29
- COOKIES=$(get-cookie --url https://github.com --browser chrome --profile "plugg.in" --render 2>/dev/null | head -c 80)
30
- echo " Output: $COOKIES..."
31
- echo ""
32
-
33
- echo "2ļøāƒ£ Compare different profiles for the same cookie:"
34
- echo ""
35
- echo " Default/Personal profile:"
36
- echo " $ get-cookie user_session github.com --browser chrome --profile \"Personal\" --render"
37
- PERSONAL=$(get-cookie user_session github.com --browser chrome --profile "Personal" --render 2>/dev/null)
38
- if [ -n "$PERSONAL" ]; then
39
- VALUE=$(echo "$PERSONAL" | cut -d'=' -f2)
40
- echo " Result: user_session=${VALUE:0:20}... (${#VALUE} chars)"
41
- else
42
- echo " Result: No user_session cookie found"
43
- fi
44
- echo ""
45
-
46
- echo " Profile 9/plugg.in profile:"
47
- echo " $ get-cookie user_session github.com --browser chrome --profile \"plugg.in\" --render"
48
- PLUGIN=$(get-cookie user_session github.com --browser chrome --profile "plugg.in" --render 2>/dev/null)
49
- if [ -n "$PLUGIN" ]; then
50
- VALUE=$(echo "$PLUGIN" | cut -d'=' -f2)
51
- echo " Result: user_session=${VALUE:0:20}... (${#VALUE} chars)"
52
- else
53
- echo " Result: No user_session cookie found"
54
- fi
55
- echo ""
56
-
57
- # Show the benefit
58
- echo "šŸ’” Benefits of Profile Selection:"
59
- echo "───────────────────────────────"
60
- echo "• Avoid cookie conflicts between profiles"
61
- echo "• Target the correct logged-in session"
62
- echo "• No need for deduplication when using specific profile"
63
- echo "• Faster queries (only searches one profile)"
64
- echo ""
65
-
66
- # Practical curl example
67
- echo "šŸ”§ Practical Example with curl:"
68
- echo "─────────────────────────────"
69
- echo ""
70
- echo "Use the correct profile for authenticated requests:"
71
- echo ""
72
- cat << 'EOF'
73
- # Get cookies from your work profile
74
- COOKIES=$(get-cookie --url https://github.com --browser chrome --profile "Work" --render)
75
- curl -H "Cookie: $COOKIES" https://github.com/settings/profile
76
-
77
- # Get cookies from your personal profile
78
- COOKIES=$(get-cookie --url https://github.com --browser chrome --profile "Personal" --render)
79
- curl -H "Cookie: $COOKIES" https://github.com/settings/profile
80
- EOF
81
- echo ""
82
-
83
- # Test with curl
84
- echo "🧪 Live Test with GitHub:"
85
- echo "──────────────────────"
86
- echo ""
87
-
88
- test_profile() {
89
- local profile=$1
90
- echo -n "Testing profile '$profile': "
91
-
92
- COOKIES=$(get-cookie --url https://github.com/settings/profile --browser chrome --profile "$profile" --render 2>/dev/null)
93
-
94
- if [ -z "$COOKIES" ]; then
95
- echo "āŒ No cookies found"
96
- return
97
- fi
98
-
99
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
100
- -H "Cookie: $COOKIES" \
101
- -H "User-Agent: Mozilla/5.0" \
102
- "https://github.com/settings/profile")
103
-
104
- if [ "$HTTP_CODE" = "200" ]; then
105
- echo "āœ… Authenticated (HTTP 200)"
106
- elif [ "$HTTP_CODE" = "302" ]; then
107
- echo "šŸ”„ Redirected to login (HTTP 302)"
108
- else
109
- echo "āš ļø HTTP $HTTP_CODE"
110
- fi
111
- }
112
-
113
- # Test each profile that might have GitHub cookies
114
- test_profile "Personal"
115
- test_profile "plugg.in"
116
- echo ""
117
-
118
- echo "šŸ“ Usage Notes:"
119
- echo "────────────"
120
- echo "• Profile names are case-insensitive"
121
- echo "• You can use either the display name (e.g., \"Personal\") or directory name (e.g., \"Default\")"
122
- echo "• If no --profile is specified, all profiles are queried"
123
- echo "• Combine with --include-all to see cookies from all profiles even when one is selected"
124
- echo ""
125
-
126
- echo "āœ… Profile selection feature is working perfectly!"
@@ -1,102 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Simple demonstration of get-cookie + curl integration
4
- echo "šŸŖ get-cookie + curl Integration Demo"
5
- echo "======================================"
6
-
7
- # First, let's verify we have cookies
8
- echo -e "\n1ļøāƒ£ Checking available cookies..."
9
- COOKIE_COUNT=$(get-cookie % github.com --output json 2>/dev/null | jq 'length')
10
- echo " Found $COOKIE_COUNT GitHub cookies"
11
-
12
- # Extract a specific cookie value
13
- echo -e "\n2ļøāƒ£ Extracting user_session cookie..."
14
- USER_SESSION=$(get-cookie user_session github.com --output json 2>/dev/null | jq -r '.[0].value' 2>/dev/null)
15
-
16
- if [ -n "$USER_SESSION" ] && [ "$USER_SESSION" != "null" ]; then
17
- echo " āœ… Got user_session cookie"
18
- echo " Value: ${USER_SESSION:0:20}... (truncated for security)"
19
-
20
- # Use the cookie with curl
21
- echo -e "\n3ļøāƒ£ Making authenticated GitHub API request..."
22
- RESPONSE=$(curl -s \
23
- -H "Cookie: user_session=$USER_SESSION" \
24
- -H "User-Agent: get-cookie-demo" \
25
- "https://api.github.com/user")
26
-
27
- # Check if we got user data
28
- LOGIN=$(echo "$RESPONSE" | jq -r '.login' 2>/dev/null)
29
- if [ -n "$LOGIN" ] && [ "$LOGIN" != "null" ]; then
30
- echo " āœ… Authenticated as: @$LOGIN"
31
-
32
- # Get more user info
33
- NAME=$(echo "$RESPONSE" | jq -r '.name' 2>/dev/null)
34
- COMPANY=$(echo "$RESPONSE" | jq -r '.company' 2>/dev/null)
35
- PUBLIC_REPOS=$(echo "$RESPONSE" | jq -r '.public_repos' 2>/dev/null)
36
-
37
- echo " Name: $NAME"
38
- [ "$COMPANY" != "null" ] && echo " Company: $COMPANY"
39
- echo " Public repos: $PUBLIC_REPOS"
40
- else
41
- echo " āš ļø API did not return user data (cookie might not work for API)"
42
- fi
43
- else
44
- echo " āŒ No user_session cookie found"
45
- fi
46
-
47
- # Example with multiple cookies
48
- echo -e "\n4ļøāƒ£ Building multi-cookie header..."
49
- COOKIES=""
50
-
51
- # Extract multiple cookies and combine them
52
- for cookie_name in "user_session" "dotcom_user" "__Host-user_session_same_site"; do
53
- COOKIE_VALUE=$(get-cookie "$cookie_name" github.com --output json 2>/dev/null | jq -r '.[0].value' 2>/dev/null)
54
- if [ -n "$COOKIE_VALUE" ] && [ "$COOKIE_VALUE" != "null" ]; then
55
- [ -n "$COOKIES" ] && COOKIES="$COOKIES; "
56
- COOKIES="$COOKIES$cookie_name=$COOKIE_VALUE"
57
- echo " āœ… Added $cookie_name"
58
- fi
59
- done
60
-
61
- if [ -n "$COOKIES" ]; then
62
- echo -e "\n5ļøāƒ£ Testing page access with cookies..."
63
- # Test accessing a protected page
64
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
65
- -H "Cookie: $COOKIES" \
66
- -H "User-Agent: Mozilla/5.0" \
67
- "https://github.com/settings/profile")
68
-
69
- if [ "$HTTP_CODE" = "200" ]; then
70
- echo " āœ… Successfully accessed settings page (HTTP 200)"
71
- elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
72
- echo " āš ļø Redirected (HTTP $HTTP_CODE) - might need more cookies"
73
- else
74
- echo " āŒ Access failed (HTTP $HTTP_CODE)"
75
- fi
76
- fi
77
-
78
- # Practical example: Download with authentication
79
- echo -e "\n6ļøāƒ£ Example: Downloading with authentication..."
80
- echo " Command to download your GitHub avatar:"
81
- if [ -n "$LOGIN" ]; then
82
- echo " curl -H \"Cookie: user_session=\$COOKIE\" -o avatar.png https://github.com/$LOGIN.png"
83
- else
84
- echo " curl -H \"Cookie: user_session=\$COOKIE\" -o avatar.png https://github.com/USERNAME.png"
85
- fi
86
-
87
- # One-liner examples
88
- echo -e "\nšŸ“ Useful one-liners:"
89
- echo "────────────────────"
90
- echo "# Get cookie value only:"
91
- echo "get-cookie user_session github.com --output json | jq -r '.[0].value'"
92
- echo ""
93
- echo "# Direct pipe to curl:"
94
- echo "curl -H \"Cookie: user_session=\$(get-cookie user_session github.com --output json | jq -r '.[0].value')\" https://api.github.com/user"
95
- echo ""
96
- echo "# Save all cookies to file:"
97
- echo "get-cookie % github.com --output json > github-cookies.json"
98
- echo ""
99
- echo "# Use with HTTPie instead of curl:"
100
- echo "http https://api.github.com/user \"Cookie:user_session=\$(get-cookie user_session github.com --output json | jq -r '.[0].value')\""
101
-
102
- echo -e "\nāœ… Demo complete!"
@@ -1,136 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Ultimate get-cookie + curl integration using --url flag
4
- echo "šŸš€ get-cookie + curl: The Perfect Integration"
5
- echo "============================================="
6
- echo ""
7
- echo "The --url flag automatically gets all cookies for a specific URL!"
8
- echo ""
9
-
10
- # Example 1: Simple one-liner for any URL
11
- echo "1ļøāƒ£ One-liner to curl any URL with cookies:"
12
- echo "─────────────────────────────────────────"
13
- echo 'curl -H "Cookie: $(get-cookie --url https://github.com/settings/profile --render)" https://github.com/settings/profile'
14
- echo ""
15
-
16
- # Example 2: Function for easy authenticated requests
17
- authenticated_curl() {
18
- local url=$1
19
- shift # Remove first argument, pass the rest to curl
20
-
21
- # Get cookies for this specific URL
22
- local cookies=$(get-cookie --url "$url" --render 2>/dev/null)
23
-
24
- if [ -n "$cookies" ]; then
25
- curl -H "Cookie: $cookies" "$@" "$url"
26
- else
27
- echo "No cookies found for $url" >&2
28
- curl "$@" "$url"
29
- fi
30
- }
31
-
32
- echo "2ļøāƒ£ Testing authenticated requests:"
33
- echo "──────────────────────────────────"
34
-
35
- # Test GitHub settings page
36
- echo "• GitHub Settings:"
37
- HTTP_CODE=$(authenticated_curl "https://github.com/settings/profile" -s -o /dev/null -w "%{http_code}")
38
- if [ "$HTTP_CODE" = "200" ]; then
39
- echo " āœ… Successfully accessed (HTTP 200)"
40
- elif [ "$HTTP_CODE" = "302" ]; then
41
- echo " āš ļø Redirected to login (HTTP 302)"
42
- else
43
- echo " āŒ Failed (HTTP $HTTP_CODE)"
44
- fi
45
-
46
- # Test Stack Overflow profile
47
- echo "• Stack Overflow Profile:"
48
- HTTP_CODE=$(authenticated_curl "https://stackoverflow.com/users/edit/current" -s -o /dev/null -w "%{http_code}")
49
- if [ "$HTTP_CODE" = "200" ]; then
50
- echo " āœ… Successfully accessed (HTTP 200)"
51
- elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "404" ]; then
52
- echo " āš ļø Not logged in or no profile (HTTP $HTTP_CODE)"
53
- else
54
- echo " āŒ Failed (HTTP $HTTP_CODE)"
55
- fi
56
-
57
- echo ""
58
- echo "3ļøāƒ£ Practical Examples:"
59
- echo "────────────────────"
60
-
61
- # Download a file with authentication
62
- echo "• Download authenticated content:"
63
- echo ' curl -H "Cookie: $(get-cookie --url https://example.com/private/file.pdf --render)" \\'
64
- echo ' -o file.pdf https://example.com/private/file.pdf'
65
-
66
- # POST request with cookies
67
- echo ""
68
- echo "• POST with authentication:"
69
- echo ' curl -X POST \\'
70
- echo ' -H "Cookie: $(get-cookie --url https://api.example.com/endpoint --render)" \\'
71
- echo ' -H "Content-Type: application/json" \\'
72
- echo ' -d '"'"'{"key": "value"}'"'"' \\'
73
- echo ' https://api.example.com/endpoint'
74
-
75
- # Follow redirects with cookies
76
- echo ""
77
- echo "• Follow redirects while maintaining cookies:"
78
- echo ' curl -L \\'
79
- echo ' -H "Cookie: $(get-cookie --url https://example.com/dashboard --render)" \\'
80
- echo ' https://example.com/dashboard'
81
-
82
- echo ""
83
- echo "4ļøāƒ£ Advanced Usage:"
84
- echo "─────────────────"
85
-
86
- # Show what cookies would be sent for different URLs
87
- echo "• Preview cookies for different URLs:"
88
- for url in "https://github.com/" "https://api.github.com/" "https://gist.github.com/"; do
89
- COOKIE_COUNT=$(get-cookie --url "$url" --output json 2>/dev/null | jq 'length // 0')
90
- echo " $url → $COOKIE_COUNT cookies"
91
- done
92
-
93
- echo ""
94
- echo "5ļøāƒ£ Shell Function for Your .bashrc/.zshrc:"
95
- echo "──────────────────────────────────────────"
96
- cat << 'EOF'
97
- # Add to your shell config for easy authenticated requests
98
- auth_curl() {
99
- local url=$1
100
- shift
101
- curl -H "Cookie: $(get-cookie --url "$url" --render 2>/dev/null)" "$@" "$url"
102
- }
103
-
104
- # Usage: auth_curl https://github.com/settings/profile -s | grep username
105
- EOF
106
-
107
- echo ""
108
- echo "6ļøāƒ£ Comparison: Manual vs --url flag:"
109
- echo "────────────────────────────────────"
110
- echo "āŒ Manual (need to know domain and cookie names):"
111
- echo ' get-cookie user_session github.com --render'
112
- echo ""
113
- echo "āœ… With --url (automatic):"
114
- echo ' get-cookie --url https://github.com/settings/profile --render'
115
- echo ""
116
- echo "The --url flag automatically:"
117
- echo " • Extracts the domain from the URL"
118
- echo " • Gets ALL relevant cookies for that domain"
119
- echo " • Handles subdomains correctly"
120
- echo " • Returns cookies in the right format for curl"
121
-
122
- echo ""
123
- echo "7ļøāƒ£ Real Example - Download your GitHub avatar:"
124
- echo "──────────────────────────────────────────────"
125
- USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2 | cut -d';' -f1)
126
- if [ -n "$USERNAME" ]; then
127
- echo "Downloading avatar for: $USERNAME"
128
- echo "Command:"
129
- echo " curl -H \"Cookie: \$(get-cookie --url https://github.com/$USERNAME.png --render)\" \\"
130
- echo " -o avatar.png https://github.com/$USERNAME.png"
131
- else
132
- echo "Not logged into GitHub"
133
- fi
134
-
135
- echo ""
136
- echo "āœ… The --url flag makes cookie extraction automatic and foolproof!"