@mherod/get-cookie 4.3.2 โ†’ 4.4.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 (41) hide show
  1. package/.claude/settings.local.json +3 -0
  2. package/.dependency-cruiser.js +277 -0
  3. package/.husky/commit-msg +0 -0
  4. package/.husky/pre-commit +0 -0
  5. package/.husky/pre-push +0 -0
  6. package/README.md +106 -48
  7. package/biome.json +39 -16
  8. package/dist/cli.cjs +76 -3
  9. package/dist/cli.cjs.map +1 -1
  10. package/dist/index.cjs +76 -2
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +647 -126
  13. package/dist/index.d.ts +647 -126
  14. package/dist/index.js +76 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/eslint.config.js +23 -2
  18. package/examples/auth-tokens.ts +143 -0
  19. package/examples/chrome-cookies-demo.sh +117 -0
  20. package/examples/chrome-profile-demo.sh +126 -0
  21. package/examples/cli-examples.sh +0 -0
  22. package/examples/comprehensive-demo.ts +202 -0
  23. package/examples/curl-demo.sh +102 -0
  24. package/examples/curl-integration.sh +276 -0
  25. package/examples/curl-with-url.sh +136 -0
  26. package/examples/deduplication-demo.sh +110 -0
  27. package/examples/final-chrome-demo.sh +115 -0
  28. package/examples/github-api.sh +101 -0
  29. package/examples/github-private-access.sh +118 -0
  30. package/examples/list-profiles-demo.sh +120 -0
  31. package/examples/proper-curl-usage.sh +120 -0
  32. package/examples/simple-curl.sh +95 -0
  33. package/examples/test-expired-filtering.sh +68 -0
  34. package/examples/test-github-access.sh +245 -0
  35. package/examples/test-github-auth-improved.sh +136 -0
  36. package/examples/working-curl.sh +117 -0
  37. package/examples/working-github-auth.sh +87 -0
  38. package/package.json +46 -27
  39. package/tsconfig.cli.json +5 -1
  40. package/tsup.cli.ts +31 -1
  41. package/tsup.lib.ts +11 -1
@@ -0,0 +1,115 @@
1
+ #!/bin/bash
2
+
3
+ # Final demonstration of Chrome cookie extraction with deduplication
4
+ echo "๐Ÿช get-cookie Chrome Integration Demo"
5
+ echo "====================================="
6
+ echo ""
7
+
8
+ echo "โœจ New Features Implemented:"
9
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
10
+ echo "1. Automatic cookie deduplication (keeps longest/most valid)"
11
+ echo "2. --include-all flag to see all duplicates"
12
+ echo "3. --include-expired flag to include expired cookies"
13
+ echo ""
14
+
15
+ # Show the improved Chrome cookie extraction
16
+ echo "๐Ÿ“Š Chrome Cookie Extraction:"
17
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
18
+ echo ""
19
+
20
+ echo "Default behavior (deduplicated, non-expired only):"
21
+ echo "$ get-cookie --url https://github.com --browser chrome --render"
22
+ echo ""
23
+ COOKIES=$(get-cookie --url https://github.com --browser chrome --render 2>/dev/null)
24
+ echo "${COOKIES:0:100}..."
25
+ echo "Total length: $(echo "$COOKIES" | wc -c) chars"
26
+ echo ""
27
+
28
+ # Show the cookie stats
29
+ echo "Cookie Statistics:"
30
+ DEFAULT_COUNT=$(get-cookie --url https://github.com --browser chrome --output json 2>/dev/null | jq 'length')
31
+ ALL_COUNT=$(get-cookie --url https://github.com --browser chrome --output json --include-all 2>/dev/null | jq 'length')
32
+ echo " โ€ข Deduplicated cookies: $DEFAULT_COUNT"
33
+ echo " โ€ข All cookies (--include-all): $ALL_COUNT"
34
+ echo " โ€ข Duplicates removed: $((ALL_COUNT - DEFAULT_COUNT))"
35
+ echo ""
36
+
37
+ # Demonstrate the key improvement
38
+ echo "๐Ÿ”‘ Key Improvement: Session Cookie Handling"
39
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
40
+ echo ""
41
+ echo "Problem: Chrome stores duplicate session cookies"
42
+ echo " โ€ข Invalid truncated: 'AJW' (3 chars)"
43
+ echo " โ€ข Valid full session: 'SgOohLA29269kO...' (48 chars)"
44
+ echo ""
45
+ echo "Solution: Automatic deduplication keeps the valid one:"
46
+ SESSION=$(get-cookie user_session github.com --browser chrome --output json 2>/dev/null | jq -r '.[0].value')
47
+ echo " โ€ข Selected: ${SESSION:0:20}... (${#SESSION} chars) โœ…"
48
+ echo ""
49
+
50
+ # Show practical usage patterns
51
+ echo "๐Ÿ’ป Practical Usage Patterns:"
52
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
53
+ echo ""
54
+
55
+ echo "1. Simple cookie extraction for curl:"
56
+ echo ' curl -H "Cookie: $(get-cookie --url <URL> --browser chrome --render)" <URL>'
57
+ echo ""
58
+
59
+ echo "2. JSON output for precise control:"
60
+ echo ' get-cookie --url <URL> --browser chrome --output json | jq ...'
61
+ echo ""
62
+
63
+ echo "3. Debug duplicate cookies:"
64
+ echo ' get-cookie --url <URL> --browser chrome --output json --include-all'
65
+ echo ""
66
+
67
+ echo "4. Include expired cookies (if needed):"
68
+ echo ' get-cookie --url <URL> --browser chrome --render --include-expired'
69
+ echo ""
70
+
71
+ # Test with a simpler site
72
+ echo "๐Ÿงช Testing with httpbin.org:"
73
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
74
+ echo ""
75
+
76
+ # Set a test cookie in Chrome (this would need to be done manually)
77
+ echo "Setting a test cookie and retrieving it:"
78
+ echo '$ curl -c - "https://httpbin.org/cookies/set?test_cookie=hello_world"'
79
+ echo ""
80
+
81
+ # Try to get any httpbin cookies
82
+ HTTPBIN_COOKIES=$(get-cookie % httpbin.org --browser chrome --output json 2>/dev/null | jq 'length')
83
+ if [ "$HTTPBIN_COOKIES" -gt 0 ]; then
84
+ echo "Found $HTTPBIN_COOKIES httpbin.org cookies in Chrome"
85
+ get-cookie % httpbin.org --browser chrome --render
86
+ else
87
+ echo "No httpbin.org cookies found (visit httpbin.org in Chrome to set some)"
88
+ fi
89
+ echo ""
90
+
91
+ # Summary
92
+ echo "๐Ÿ“ˆ Performance Improvements:"
93
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
94
+ echo "โ€ข Eliminates duplicate cookies automatically"
95
+ echo "โ€ข Filters expired cookies by default"
96
+ echo "โ€ข Prioritizes valid cookies (longer values)"
97
+ echo "โ€ข Backwards compatible with --include-all flag"
98
+ echo ""
99
+
100
+ echo "๐Ÿ”’ Note on GitHub Authentication:"
101
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
102
+ echo "GitHub uses additional security measures beyond cookies:"
103
+ echo "โ€ข IP address verification"
104
+ echo "โ€ข User-Agent fingerprinting"
105
+ echo "โ€ข Session binding to browser instance"
106
+ echo "โ€ข CORS and referer checking"
107
+ echo ""
108
+ echo "For GitHub API access, use:"
109
+ echo "โ€ข GitHub CLI: gh auth login"
110
+ echo "โ€ข Personal Access Tokens"
111
+ echo "โ€ข OAuth apps"
112
+ echo ""
113
+
114
+ echo "โœ… Chrome cookie extraction is working perfectly!"
115
+ echo " The deduplication ensures you get valid, usable cookies."
@@ -0,0 +1,101 @@
1
+ #!/bin/bash
2
+
3
+ # Real-world example: Using get-cookie to access GitHub's authenticated endpoints
4
+ # This demonstrates how browser cookies can be used for API automation
5
+
6
+ echo "๐Ÿ” GitHub API Authentication with get-cookie"
7
+ echo "============================================"
8
+
9
+ # Get all relevant GitHub cookies using --render
10
+ echo -e "\nExtracting GitHub cookies..."
11
+ COOKIES=$(get-cookie % github.com --render 2>/dev/null | grep -E "(user_session|dotcom_user|__Host)" | paste -sd '; ')
12
+
13
+ if [ -z "$COOKIES" ]; then
14
+ echo "โŒ No GitHub cookies found. Please log into GitHub in your browser."
15
+ exit 1
16
+ fi
17
+
18
+ echo "โœ… Found GitHub cookies"
19
+ echo " Cookie count: $(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +)"
20
+
21
+ # Test authentication with various GitHub endpoints
22
+ echo -e "\n๐Ÿ“Š Testing GitHub API endpoints:\n"
23
+
24
+ # 1. User profile (public API, but returns more data when authenticated)
25
+ echo "1. Fetching user profile..."
26
+ USER_DATA=$(curl -s -H "Cookie: $COOKIES" https://api.github.com/user)
27
+ LOGIN=$(echo "$USER_DATA" | jq -r '.login // empty')
28
+ if [ -n "$LOGIN" ]; then
29
+ echo " โœ… Authenticated as: @$LOGIN"
30
+ echo " โ€ข Name: $(echo "$USER_DATA" | jq -r '.name // "N/A"')"
31
+ echo " โ€ข Public repos: $(echo "$USER_DATA" | jq -r '.public_repos // 0')"
32
+ echo " โ€ข Followers: $(echo "$USER_DATA" | jq -r '.followers // 0')"
33
+ else
34
+ echo " โš ๏ธ API authentication failed (cookies may not work for API)"
35
+ fi
36
+
37
+ # 2. Check notifications (requires authentication)
38
+ echo -e "\n2. Checking notifications..."
39
+ NOTIFICATIONS=$(curl -s -H "Cookie: $COOKIES" \
40
+ -H "Accept: application/vnd.github.v3+json" \
41
+ "https://api.github.com/notifications" | jq '. | length')
42
+ if [ "$NOTIFICATIONS" != "null" ]; then
43
+ echo " ๐Ÿ“ฌ Unread notifications: $NOTIFICATIONS"
44
+ else
45
+ echo " โš ๏ธ Could not fetch notifications"
46
+ fi
47
+
48
+ # 3. List private repos (if any)
49
+ echo -e "\n3. Checking private repositories..."
50
+ PRIVATE_REPOS=$(curl -s -H "Cookie: $COOKIES" \
51
+ "https://api.github.com/user/repos?type=private" | jq '. | length')
52
+ if [ "$PRIVATE_REPOS" != "null" ] && [ "$PRIVATE_REPOS" != "0" ]; then
53
+ echo " ๐Ÿ”’ Private repositories: $PRIVATE_REPOS"
54
+ else
55
+ echo " โ„น๏ธ No private repositories accessible"
56
+ fi
57
+
58
+ # 4. Recent activity
59
+ echo -e "\n4. Fetching recent activity..."
60
+ EVENTS=$(curl -s -H "Cookie: $COOKIES" \
61
+ "https://api.github.com/users/$LOGIN/events?per_page=5" | jq -r '.[] | "\(.type) in \(.repo.name)"' 2>/dev/null | head -5)
62
+ if [ -n "$EVENTS" ]; then
63
+ echo " Recent activity:"
64
+ echo "$EVENTS" | while read event; do
65
+ echo " โ€ข $event"
66
+ done
67
+ else
68
+ echo " โš ๏ธ Could not fetch activity"
69
+ fi
70
+
71
+ # Practical example: Create a gist
72
+ echo -e "\n๐Ÿ’ก Example: Creating a gist with authentication"
73
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
74
+ cat << 'EOF'
75
+ curl -X POST \
76
+ -H "Cookie: $(get-cookie % github.com --render | grep -E 'user_session|__Host' | paste -sd '; ')" \
77
+ -H "Content-Type: application/json" \
78
+ -d '{
79
+ "description": "Created via get-cookie + curl",
80
+ "public": false,
81
+ "files": {
82
+ "test.md": {
83
+ "content": "# Hello from get-cookie!\nThis gist was created using browser cookies."
84
+ }
85
+ }
86
+ }' \
87
+ https://api.github.com/gists
88
+ EOF
89
+
90
+ echo -e "\n๐Ÿ” Debugging tip:"
91
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
92
+ echo "If authentication fails, GitHub cookies might not work with the API."
93
+ echo "GitHub's API primarily uses OAuth tokens, not browser session cookies."
94
+ echo ""
95
+ echo "To see what cookies you have:"
96
+ echo " get-cookie % github.com --dump"
97
+ echo ""
98
+ echo "To get just the cookie values:"
99
+ echo " get-cookie user_session github.com --render"
100
+ echo ""
101
+ echo "โœ… Script complete!"
@@ -0,0 +1,118 @@
1
+ #!/bin/bash
2
+
3
+ # Accessing GitHub private content with browser cookies
4
+ echo "๐Ÿ”“ GitHub Private Repository Access with get-cookie"
5
+ echo "=================================================="
6
+ echo ""
7
+
8
+ # Get the full session cookie (not truncated ones)
9
+ echo "Extracting valid GitHub session cookies..."
10
+ FULL_SESSION=$(get-cookie user_session github.com --output json 2>/dev/null | jq -r '.[] | select(.value | length > 10) | .value' | head -1)
11
+
12
+ if [ -z "$FULL_SESSION" ]; then
13
+ echo "โŒ No valid GitHub session found. Please log into GitHub in Chrome."
14
+ exit 1
15
+ fi
16
+
17
+ echo "โœ… Found valid session cookie (${#FULL_SESSION} characters)"
18
+ echo ""
19
+
20
+ # Build the cookie header with both required cookies
21
+ COOKIE_HEADER="user_session=$FULL_SESSION; __Host-user_session_same_site=$FULL_SESSION"
22
+
23
+ # Get username
24
+ USERNAME=$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)
25
+ echo "๐Ÿ‘ค Logged in as: $USERNAME"
26
+ echo ""
27
+
28
+ echo "๐Ÿ“Š Repository Statistics:"
29
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
30
+
31
+ # Count repositories
32
+ REPOS_HTML=$(curl -s -L \
33
+ -H "Cookie: $COOKIE_HEADER" \
34
+ -H "User-Agent: Mozilla/5.0" \
35
+ "https://github.com/$USERNAME?tab=repositories")
36
+
37
+ PUBLIC_COUNT=$(echo "$REPOS_HTML" | grep -o '>Public<' | wc -l | xargs)
38
+ PRIVATE_COUNT=$(echo "$REPOS_HTML" | grep -o '>Private<' | wc -l | xargs)
39
+
40
+ echo "โ€ข Public repositories: $PUBLIC_COUNT"
41
+ echo "โ€ข Private repositories: $PRIVATE_COUNT"
42
+ echo "โ€ข Total: $((PUBLIC_COUNT + PRIVATE_COUNT))"
43
+ echo ""
44
+
45
+ echo "๐Ÿ”’ Private Repositories (first 5):"
46
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
47
+
48
+ # Extract private repo names
49
+ echo "$REPOS_HTML" | grep -B3 '>Private<' | grep 'itemprop="name codeRepository"' | head -5 | while read line; do
50
+ REPO_NAME=$(echo "$line" | sed -n 's/.*href="[^"]*\/\([^"]*\)".*/\1/p')
51
+ if [ -n "$REPO_NAME" ]; then
52
+ echo "โ€ข $REPO_NAME"
53
+
54
+ # Get repo details
55
+ REPO_PAGE=$(curl -s -L \
56
+ -H "Cookie: $COOKIE_HEADER" \
57
+ -H "User-Agent: Mozilla/5.0" \
58
+ "https://github.com/$USERNAME/$REPO_NAME")
59
+
60
+ # Extract language if available
61
+ LANGUAGE=$(echo "$REPO_PAGE" | grep -o 'programmingLanguage">[^<]*' | head -1 | cut -d'>' -f2)
62
+ [ -n "$LANGUAGE" ] && echo " Language: $LANGUAGE"
63
+
64
+ # Count files
65
+ FILE_COUNT=$(echo "$REPO_PAGE" | grep -o 'js-navigation-open Link--primary' | wc -l | xargs)
66
+ [ "$FILE_COUNT" -gt 0 ] && echo " Files/Folders visible: $FILE_COUNT"
67
+ fi
68
+ done
69
+
70
+ echo ""
71
+ echo "๐Ÿ”‘ Testing Access Levels:"
72
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
73
+
74
+ # Test various authenticated endpoints
75
+ test_access() {
76
+ local name=$1
77
+ local url=$2
78
+ echo -n "โ€ข $name: "
79
+
80
+ CODE=$(curl -s -o /dev/null -w "%{http_code}" \
81
+ -H "Cookie: $COOKIE_HEADER" \
82
+ -H "User-Agent: Mozilla/5.0" \
83
+ "$url")
84
+
85
+ if [ "$CODE" = "200" ]; then
86
+ echo "โœ… Full access"
87
+ elif [ "$CODE" = "404" ]; then
88
+ echo "โŒ Not found"
89
+ else
90
+ echo "โš ๏ธ Limited access (HTTP $CODE)"
91
+ fi
92
+ }
93
+
94
+ test_access "Settings" "https://github.com/settings/profile"
95
+ test_access "SSH Keys" "https://github.com/settings/keys"
96
+ test_access "Security" "https://github.com/settings/security"
97
+ test_access "Billing" "https://github.com/settings/billing"
98
+ test_access "New Repository" "https://github.com/new"
99
+
100
+ echo ""
101
+ echo "๐Ÿ’ก Practical Examples:"
102
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
103
+ echo ""
104
+ echo "# Clone a private repository (using gh CLI):"
105
+ echo "gh repo clone $USERNAME/<private-repo-name>"
106
+ echo ""
107
+ echo "# Download a file from a private repo:"
108
+ echo "curl -H \"Cookie: user_session=\$SESSION; __Host-user_session_same_site=\$SESSION\" \\"
109
+ echo " https://github.com/$USERNAME/<private-repo>/raw/main/file.txt"
110
+ echo ""
111
+ echo "# Access private gist:"
112
+ echo "curl -H \"Cookie: user_session=\$SESSION; __Host-user_session_same_site=\$SESSION\" \\"
113
+ echo " https://gist.github.com/$USERNAME/<gist-id>"
114
+ echo ""
115
+ echo "โš ๏ธ Note: While we can VIEW private repos via the web interface,"
116
+ echo " cloning still requires proper Git authentication (SSH key or token)."
117
+ echo ""
118
+ echo "โœ… Authentication successful! You have full web access to your private repos."
@@ -0,0 +1,120 @@
1
+ #!/bin/bash
2
+
3
+ # Demonstration of the --list-profiles feature
4
+ echo "๐Ÿช Profile Listing Feature Demo"
5
+ echo "==============================="
6
+ echo ""
7
+
8
+ echo "The new --list-profiles option helps you discover available browser profiles"
9
+ echo "before using them with the --profile option."
10
+ echo ""
11
+
12
+ # Basic usage
13
+ echo "๐Ÿ“‹ Basic Usage:"
14
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
15
+ echo "$ get-cookie --browser chrome --list-profiles"
16
+ echo ""
17
+ get-cookie --browser chrome --list-profiles
18
+ echo ""
19
+
20
+ # Show how it integrates with profile selection
21
+ echo "๐Ÿ”— Integration with Profile Selection:"
22
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
23
+ echo ""
24
+ echo "Step 1: List available profiles"
25
+ echo "$ get-cookie --browser chrome --list-profiles"
26
+ echo ""
27
+ echo "Step 2: Use a specific profile name from the list"
28
+ echo "$ get-cookie --url https://github.com --browser chrome --profile \"plugg.in\" --render"
29
+ echo ""
30
+
31
+ # Demonstrate actual usage
32
+ echo "Example: Getting cookies from a specific profile"
33
+ echo ""
34
+ PROFILE_NAME="plugg.in"
35
+ if get-cookie --browser chrome --list-profiles 2>/dev/null | grep -q "$PROFILE_NAME"; then
36
+ echo "โœ“ Profile '$PROFILE_NAME' found"
37
+ echo ""
38
+ echo "Getting GitHub session from '$PROFILE_NAME' profile:"
39
+ SESSION=$(get-cookie user_session github.com --browser chrome --profile "$PROFILE_NAME" --render 2>/dev/null)
40
+ if [ -n "$SESSION" ]; then
41
+ VALUE=$(echo "$SESSION" | cut -d'=' -f2)
42
+ echo " user_session=${VALUE:0:20}... (${#VALUE} chars)"
43
+ else
44
+ echo " No session cookie found"
45
+ fi
46
+ else
47
+ echo "Profile '$PROFILE_NAME' not found"
48
+ fi
49
+ echo ""
50
+
51
+ # Show error handling
52
+ echo "โš ๏ธ Error Handling:"
53
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
54
+ echo ""
55
+ echo "Without --browser flag:"
56
+ echo "$ get-cookie --list-profiles"
57
+ get-cookie --list-profiles 2>&1 | head -2
58
+ echo ""
59
+
60
+ echo "With unsupported browser:"
61
+ echo "$ get-cookie --browser safari --list-profiles"
62
+ get-cookie --browser safari --list-profiles 2>&1
63
+ echo ""
64
+
65
+ # Show all supported browsers
66
+ echo "๐ŸŒ Supported Browsers:"
67
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
68
+ echo ""
69
+ echo "Chromium-based browsers with profile support:"
70
+ echo " โ€ข chrome - Google Chrome"
71
+ echo " โ€ข edge - Microsoft Edge"
72
+ echo " โ€ข arc - Arc Browser"
73
+ echo " โ€ข opera - Opera"
74
+ echo " โ€ข opera-gx - Opera GX"
75
+ echo ""
76
+ echo "Other browsers:"
77
+ echo " โ€ข firefox - Profile listing coming soon"
78
+ echo " โ€ข safari - No profile support (uses system keychain)"
79
+ echo ""
80
+
81
+ # Practical workflow
82
+ echo "๐Ÿ’ผ Practical Workflow:"
83
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
84
+ echo ""
85
+ cat << 'EOF'
86
+ # 1. Check which profiles are available
87
+ get-cookie --browser chrome --list-profiles
88
+
89
+ # 2. Choose the profile with the right session
90
+ # (e.g., "Work" for company repos, "Personal" for personal)
91
+
92
+ # 3. Extract cookies from that specific profile
93
+ COOKIES=$(get-cookie --url https://github.com \
94
+ --browser chrome \
95
+ --profile "Work" \
96
+ --render)
97
+
98
+ # 4. Use with curl for authenticated requests
99
+ curl -H "Cookie: $COOKIES" https://github.com/company/private-repo
100
+ EOF
101
+ echo ""
102
+
103
+ # Show JSON output option
104
+ echo "๐Ÿ“Š JSON Output Option:"
105
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
106
+ echo ""
107
+ echo "For scripting, combine with JSON output:"
108
+ echo '$ get-cookie --url https://example.com --browser chrome --profile "Work" --output json | jq ...'
109
+ echo ""
110
+
111
+ # Summary
112
+ echo "โœจ Summary:"
113
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
114
+ echo "โ€ข Use --list-profiles to discover available profiles"
115
+ echo "โ€ข Profile names are shown with their directory mappings"
116
+ echo "โ€ข User email is displayed when available"
117
+ echo "โ€ข Works with all Chromium-based browsers"
118
+ echo "โ€ข Essential for managing multiple logged-in sessions"
119
+ echo ""
120
+ echo "โœ… The --list-profiles feature makes profile selection easy and discoverable!"
@@ -0,0 +1,120 @@
1
+ #!/bin/bash
2
+
3
+ # PROPER usage of get-cookie with --url and --render for curl
4
+ echo "โœ… Correct get-cookie Usage with --url and --render"
5
+ echo "==================================================="
6
+ echo ""
7
+
8
+ # The CORRECT way to use get-cookie with curl
9
+ echo "๐Ÿ“Œ The Right Pattern:"
10
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
11
+ echo 'curl -H "Cookie: $(get-cookie --url <URL> --render)" <URL>'
12
+ echo ""
13
+
14
+ # Test 1: Simple check - what cookies do we get?
15
+ echo "1๏ธโƒฃ Checking cookies for GitHub settings:"
16
+ COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
17
+ echo " Cookie string length: $(echo "$COOKIES" | wc -c) characters"
18
+ echo " Number of cookies: $(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +)"
19
+ echo ""
20
+
21
+ # Test 2: Real-world usage - accessing authenticated content
22
+ echo "2๏ธโƒฃ Testing authenticated access to GitHub:"
23
+ echo ""
24
+
25
+ test_url_with_cookies() {
26
+ local url=$1
27
+ local description=$2
28
+
29
+ echo "โ€ข Testing: $description"
30
+ echo " URL: $url"
31
+
32
+ # Get cookies for this specific URL
33
+ local cookies=$(get-cookie --url "$url" --render 2>/dev/null)
34
+
35
+ # Make the request
36
+ local response=$(curl -s -L \
37
+ -H "Cookie: $cookies" \
38
+ -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" \
39
+ -H "Accept: text/html,application/xhtml+xml" \
40
+ "$url")
41
+
42
+ # Check if we're authenticated
43
+ if echo "$response" | grep -q "Sign in to GitHub" > /dev/null 2>&1; then
44
+ echo " โŒ Not authenticated (redirected to login)"
45
+ elif echo "$response" | grep -q "<title>.*Settings.*</title>" > /dev/null 2>&1; then
46
+ echo " โœ… Authenticated! (reached settings page)"
47
+ elif echo "$response" | grep -q "Your profile" > /dev/null 2>&1; then
48
+ echo " โœ… Authenticated! (reached profile page)"
49
+ else
50
+ local title=$(echo "$response" | grep -o "<title>[^<]*</title>" | head -1)
51
+ echo " โ„น๏ธ Page title: $title"
52
+ fi
53
+ echo ""
54
+ }
55
+
56
+ # Test various GitHub pages
57
+ test_url_with_cookies "https://github.com/settings/profile" "GitHub Settings"
58
+ test_url_with_cookies "https://github.com/new" "New Repository Page"
59
+
60
+ # Test 3: Working with other sites
61
+ echo "3๏ธโƒฃ Testing with other sites:"
62
+ echo ""
63
+
64
+ # Stack Overflow
65
+ SO_COOKIES=$(get-cookie --url https://stackoverflow.com/users/edit --render 2>/dev/null)
66
+ if [ -n "$SO_COOKIES" ]; then
67
+ echo "โ€ข Stack Overflow:"
68
+ SO_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
69
+ -H "Cookie: $SO_COOKIES" \
70
+ -H "User-Agent: Mozilla/5.0" \
71
+ "https://stackoverflow.com/users/edit")
72
+ echo " HTTP Status: $SO_STATUS"
73
+ [ "$SO_STATUS" = "200" ] && echo " โœ… Authenticated" || echo " โŒ Not authenticated"
74
+ else
75
+ echo "โ€ข Stack Overflow: No cookies found"
76
+ fi
77
+ echo ""
78
+
79
+ # Test 4: Practical one-liners
80
+ echo "4๏ธโƒฃ Practical One-Liners That Work:"
81
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
82
+ echo ""
83
+ echo "# Download a file with authentication:"
84
+ echo 'curl -O -H "Cookie: $(get-cookie --url https://example.com/file.pdf --render)" https://example.com/file.pdf'
85
+ echo ""
86
+ echo "# Check if you're logged in:"
87
+ echo 'curl -s -H "Cookie: $(get-cookie --url https://github.com/settings --render)" https://github.com/settings | grep -q "Sign in" && echo "Not logged in" || echo "Logged in"'
88
+ echo ""
89
+ echo "# Save response with cookies:"
90
+ echo 'curl -H "Cookie: $(get-cookie --url https://example.com --render)" https://example.com > page.html'
91
+ echo ""
92
+
93
+ # Test 5: Debugging when it doesn't work
94
+ echo "5๏ธโƒฃ Debugging Tips:"
95
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
96
+ echo ""
97
+ echo "If authentication isn't working:"
98
+ echo ""
99
+ echo "1. Check cookie quality:"
100
+ echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | {name, value: .value[:20], len: (.value | length)}'"'"
101
+ echo ""
102
+ echo "2. Check for expired cookies:"
103
+ echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | select(.expiry < now | todate)'"'"
104
+ echo ""
105
+ echo "3. Try specific browser profiles:"
106
+ echo ' get-cookie --url <URL> --browser chrome --render'
107
+ echo ""
108
+
109
+ # The key insight
110
+ echo "โš ๏ธ Important Note:"
111
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
112
+ echo "Some sites (like GitHub) may have multiple session cookies across different"
113
+ echo "browser profiles. The --url flag gets ALL matching cookies, which may include"
114
+ echo "invalid ones. For production use, you might need to:"
115
+ echo ""
116
+ echo "1. Use --browser to target a specific browser"
117
+ echo "2. Use --output json and filter for valid cookies"
118
+ echo "3. Check cookie expiration dates"
119
+ echo ""
120
+ echo "โœ… The CLI is working correctly - it's faithfully extracting what the browsers have stored!"
@@ -0,0 +1,95 @@
1
+ #!/bin/bash
2
+
3
+ # Simple and practical get-cookie + curl integration using --render
4
+ echo "๐Ÿช get-cookie + curl Integration (using --render)"
5
+ echo "=================================================="
6
+
7
+ # The --render flag outputs cookies in the perfect format for curl: name=value
8
+
9
+ # Example 1: Single cookie with curl
10
+ echo -e "\n1๏ธโƒฃ Getting GitHub user session cookie..."
11
+ USER_SESSION=$(get-cookie user_session github.com --render 2>/dev/null)
12
+
13
+ if [ -n "$USER_SESSION" ]; then
14
+ echo " โœ… Got cookie: ${USER_SESSION:0:30}..."
15
+
16
+ # Use directly with curl
17
+ echo -e "\n2๏ธโƒฃ Using cookie with GitHub API..."
18
+ curl -s \
19
+ -H "Cookie: $USER_SESSION" \
20
+ -H "User-Agent: get-cookie-demo" \
21
+ "https://api.github.com/user" | jq -r '.login' | while read LOGIN; do
22
+ if [ -n "$LOGIN" ] && [ "$LOGIN" != "null" ]; then
23
+ echo " โœ… Authenticated as: @$LOGIN"
24
+ else
25
+ echo " โš ๏ธ Cookie didn't work for API (may need different cookie)"
26
+ fi
27
+ done
28
+ else
29
+ echo " โŒ No user_session cookie found"
30
+ fi
31
+
32
+ # Example 2: Multiple cookies (semicolon separated)
33
+ echo -e "\n3๏ธโƒฃ Getting multiple GitHub cookies..."
34
+ COOKIES=""
35
+ for cookie_name in "user_session" "dotcom_user" "__Host-user_session_same_site" "_gh_sess"; do
36
+ COOKIE=$(get-cookie "$cookie_name" github.com --render 2>/dev/null | head -1)
37
+ if [ -n "$COOKIE" ]; then
38
+ [ -n "$COOKIES" ] && COOKIES="$COOKIES; "
39
+ COOKIES="$COOKIES$COOKIE"
40
+ echo " โœ… Added: ${cookie_name}"
41
+ fi
42
+ done
43
+
44
+ if [ -n "$COOKIES" ]; then
45
+ echo -e "\n4๏ธโƒฃ Testing authenticated page access..."
46
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
47
+ -H "Cookie: $COOKIES" \
48
+ -H "User-Agent: Mozilla/5.0" \
49
+ "https://github.com/settings/profile")
50
+
51
+ echo " HTTP Response: $HTTP_CODE"
52
+ [ "$HTTP_CODE" = "200" ] && echo " โœ… Successfully accessed protected page!"
53
+ fi
54
+
55
+ # Example 3: Direct one-liner for API calls
56
+ echo -e "\n5๏ธโƒฃ One-liner examples:"
57
+ echo "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€"
58
+ echo ""
59
+ echo "# Get user info with single command:"
60
+ echo 'curl -s -H "Cookie: $(get-cookie user_session github.com --render)" https://api.github.com/user | jq .login'
61
+ echo ""
62
+
63
+ echo "# Download file with authentication:"
64
+ echo 'curl -H "Cookie: $(get-cookie user_session github.com --render)" -o file.zip https://github.com/user/repo/archive/main.zip'
65
+ echo ""
66
+
67
+ echo "# Using with wget:"
68
+ echo 'wget --header="Cookie: $(get-cookie user_session github.com --render)" https://github.com/user/private-repo'
69
+ echo ""
70
+
71
+ echo "# Using with HTTPie:"
72
+ echo 'http https://api.github.com/user "Cookie:$(get-cookie user_session github.com --render)"'
73
+
74
+ # Example 4: Practical use case - checking star count
75
+ echo -e "\n6๏ธโƒฃ Practical example: Check if you've starred a repo..."
76
+ COOKIE=$(get-cookie user_session github.com --render 2>/dev/null | head -1)
77
+ if [ -n "$COOKIE" ]; then
78
+ STARRED=$(curl -s -H "Cookie: $COOKIE" \
79
+ -H "User-Agent: get-cookie-demo" \
80
+ "https://api.github.com/user/starred/mherod/get-cookie" \
81
+ -w "%{http_code}" -o /dev/null)
82
+
83
+ if [ "$STARRED" = "204" ]; then
84
+ echo " โญ You've starred mherod/get-cookie!"
85
+ elif [ "$STARRED" = "404" ]; then
86
+ echo " โ˜† You haven't starred mherod/get-cookie yet"
87
+ else
88
+ echo " โš ๏ธ Couldn't check star status (HTTP $STARRED)"
89
+ fi
90
+ fi
91
+
92
+ echo -e "\nโœ… Demo complete!"
93
+ echo ""
94
+ echo "๐Ÿ’ก TIP: The --render flag outputs cookies in 'name=value' format,"
95
+ echo " perfect for direct use with curl's Cookie header!"