@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,68 @@
1
+ #!/bin/bash
2
+
3
+ # Test the expired cookie filtering feature
4
+ echo "šŸ” Testing Expired Cookie Filtering"
5
+ echo "===================================="
6
+ echo ""
7
+
8
+ # Test 1: Check default behavior (should filter expired)
9
+ echo "1ļøāƒ£ Default behavior (filters expired cookies):"
10
+ echo "─────────────────────────────────────────────"
11
+ DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
12
+ echo " Cookies returned: $DEFAULT_COUNT"
13
+ echo ""
14
+
15
+ # Test 2: Check with --include-expired flag
16
+ echo "2ļøāƒ£ With --include-expired flag:"
17
+ echo "────────────────────────────────"
18
+ WITH_EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
19
+ echo " Cookies returned: $WITH_EXPIRED_COUNT"
20
+ echo ""
21
+
22
+ # Test 3: Compare the difference
23
+ echo "3ļøāƒ£ Analysis:"
24
+ echo "───────────"
25
+ if [ "$WITH_EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
26
+ DIFF=$((WITH_EXPIRED_COUNT - DEFAULT_COUNT))
27
+ echo " āœ… Filtering is working! Removed $DIFF expired cookies"
28
+ else
29
+ echo " ā„¹ļø No expired cookies found (or same count)"
30
+ fi
31
+ echo ""
32
+
33
+ # Test 4: Show example cookies with expiry info
34
+ echo "4ļøāƒ£ Sample cookies with expiry info:"
35
+ echo "──────────────────────────────────"
36
+ echo "Default (non-expired only):"
37
+ get-cookie --url https://github.com --output json 2>/dev/null | jq -r '.[:3] | .[] | " • \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"'
38
+ echo ""
39
+
40
+ echo "With expired included:"
41
+ get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq -r '.[:3] | .[] | " • \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"'
42
+ echo ""
43
+
44
+ # Test 5: Practical curl test
45
+ echo "5ļøāƒ£ Practical test with curl:"
46
+ echo "──────────────────────────"
47
+ echo "Testing GitHub authentication with filtered cookies..."
48
+ COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
49
+ RESPONSE=$(curl -s -L \
50
+ -H "Cookie: $COOKIES" \
51
+ -H "User-Agent: Mozilla/5.0" \
52
+ "https://github.com/settings/profile" | grep -o "<title>[^<]*</title>" | head -1)
53
+
54
+ if echo "$RESPONSE" | grep -q "Your profile"; then
55
+ echo "āœ… Authentication successful with filtered cookies!"
56
+ elif echo "$RESPONSE" | grep -q "Sign in"; then
57
+ echo "āŒ Authentication failed (redirected to sign in)"
58
+ else
59
+ echo "ā„¹ļø Response: $RESPONSE"
60
+ fi
61
+ echo ""
62
+
63
+ echo "šŸ’” Summary:"
64
+ echo "─────────"
65
+ echo "The --include-expired flag controls whether expired cookies are included."
66
+ echo "By default, expired cookies are filtered out for better authentication success."
67
+ echo ""
68
+ echo "āœ… Feature is working as expected!"
@@ -0,0 +1,245 @@
1
+ #!/bin/bash
2
+
3
+ # Test what GitHub content we can actually access with browser cookies
4
+ echo "šŸ” Testing GitHub Private Access with Browser Cookies"
5
+ echo "====================================================="
6
+ echo ""
7
+
8
+ # Get all GitHub cookies
9
+ COOKIES=$(get-cookie --url https://github.com --render 2>/dev/null)
10
+
11
+ if [ -z "$COOKIES" ]; then
12
+ echo "āŒ No GitHub cookies found. Please log into GitHub in your browser."
13
+ exit 1
14
+ fi
15
+
16
+ echo "āœ… Found GitHub cookies ($(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +) cookies)"
17
+ echo ""
18
+
19
+ # Extract username from cookies
20
+ USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2 | cut -d';' -f1)
21
+ if [ -n "$USERNAME" ]; then
22
+ echo "šŸ‘¤ Detected GitHub username: $USERNAME"
23
+ else
24
+ echo "āš ļø Could not detect username from cookies"
25
+ USERNAME="mherod" # fallback for testing
26
+ fi
27
+
28
+ echo ""
29
+ echo "Testing various GitHub endpoints..."
30
+ echo "────────────────────────────────────"
31
+
32
+ # Function to test GitHub endpoints
33
+ test_endpoint() {
34
+ local name=$1
35
+ local url=$2
36
+ local check_string=$3
37
+
38
+ echo -n "• $name: "
39
+
40
+ RESPONSE=$(curl -s -L \
41
+ -H "Cookie: $COOKIES" \
42
+ -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
43
+ -H "Accept: text/html,application/xhtml+xml" \
44
+ "$url")
45
+
46
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
47
+ -H "Cookie: $COOKIES" \
48
+ -H "User-Agent: Mozilla/5.0" \
49
+ "$url")
50
+
51
+ if echo "$RESPONSE" | grep -q "$check_string" > /dev/null 2>&1; then
52
+ echo "āœ… Authenticated (HTTP $HTTP_CODE)"
53
+ return 0
54
+ elif [ "$HTTP_CODE" = "200" ]; then
55
+ echo "āš ļø Accessible but not authenticated (HTTP 200)"
56
+ return 1
57
+ elif [ "$HTTP_CODE" = "404" ]; then
58
+ echo "āŒ Not found (HTTP 404)"
59
+ return 1
60
+ elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
61
+ echo "šŸ”„ Redirected - not authenticated (HTTP $HTTP_CODE)"
62
+ return 1
63
+ else
64
+ echo "āŒ Failed (HTTP $HTTP_CODE)"
65
+ return 1
66
+ fi
67
+ }
68
+
69
+ # Test public profile (should work either way)
70
+ test_endpoint "Public profile" \
71
+ "https://github.com/$USERNAME" \
72
+ "Follow"
73
+
74
+ # Test settings page (requires authentication)
75
+ test_endpoint "Settings page" \
76
+ "https://github.com/settings/profile" \
77
+ "Public profile"
78
+
79
+ # Test notifications (requires authentication)
80
+ test_endpoint "Notifications" \
81
+ "https://github.com/notifications" \
82
+ "notifications"
83
+
84
+ # Test security settings (requires authentication)
85
+ test_endpoint "Security settings" \
86
+ "https://github.com/settings/security" \
87
+ "Two-factor"
88
+
89
+ # Test SSH keys page (requires authentication)
90
+ test_endpoint "SSH keys" \
91
+ "https://github.com/settings/keys" \
92
+ "SSH keys"
93
+
94
+ echo ""
95
+ echo "Testing repository access..."
96
+ echo "────────────────────────────"
97
+
98
+ # Test accessing this repository (get-cookie)
99
+ echo -n "• get-cookie repo: "
100
+ REPO_RESPONSE=$(curl -s -L \
101
+ -H "Cookie: $COOKIES" \
102
+ -H "User-Agent: Mozilla/5.0" \
103
+ "https://github.com/$USERNAME/get-cookie")
104
+
105
+ if echo "$REPO_RESPONSE" | grep -q "Code" > /dev/null 2>&1; then
106
+ echo "āœ… Can access"
107
+
108
+ # Check if we can see the clone button (indicates authenticated access)
109
+ if echo "$REPO_RESPONSE" | grep -q "Use Git or checkout with SVN" > /dev/null 2>&1; then
110
+ echo " └─ āœ… Authenticated view (can see clone options)"
111
+ fi
112
+ else
113
+ echo "āŒ Cannot access"
114
+ fi
115
+
116
+ # Test creating a new repository page (requires authentication)
117
+ echo -n "• New repo page: "
118
+ NEW_REPO_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
119
+ -H "Cookie: $COOKIES" \
120
+ -H "User-Agent: Mozilla/5.0" \
121
+ "https://github.com/new")
122
+
123
+ if [ "$NEW_REPO_CODE" = "200" ]; then
124
+ echo "āœ… Can access (authenticated)"
125
+ else
126
+ echo "āŒ Cannot access (HTTP $NEW_REPO_CODE)"
127
+ fi
128
+
129
+ echo ""
130
+ echo "Testing private repository detection..."
131
+ echo "───────────────────────────────────────"
132
+
133
+ # Try to list repositories including private ones
134
+ echo "Attempting to fetch repository list..."
135
+
136
+ REPOS_PAGE=$(curl -s -L \
137
+ -H "Cookie: $COOKIES" \
138
+ -H "User-Agent: Mozilla/5.0" \
139
+ "https://github.com/$USERNAME?tab=repositories")
140
+
141
+ # Count repositories visible
142
+ PUBLIC_COUNT=$(echo "$REPOS_PAGE" | grep -o 'itemprop="name codeRepository"' | wc -l | xargs)
143
+ echo "• Repositories visible: $PUBLIC_COUNT"
144
+
145
+ # Check if we can see private repo indicators
146
+ if echo "$REPOS_PAGE" | grep -q "Private" > /dev/null 2>&1; then
147
+ echo "• āœ… Can see private repository badges"
148
+ PRIVATE_COUNT=$(echo "$REPOS_PAGE" | grep -o '>Private<' | wc -l | xargs)
149
+ echo "• Private repositories visible: $PRIVATE_COUNT"
150
+ else
151
+ echo "• āš ļø No private repository badges found (may not have any or not authenticated)"
152
+ fi
153
+
154
+ echo ""
155
+ echo "Testing specific private repository (if you have one)..."
156
+ echo "────────────────────────────────────────────────────────"
157
+
158
+ # Function to test a specific private repo
159
+ test_private_repo() {
160
+ local repo_name=$1
161
+ echo -n "• Testing $USERNAME/$repo_name: "
162
+
163
+ REPO_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
164
+ -H "Cookie: $COOKIES" \
165
+ -H "User-Agent: Mozilla/5.0" \
166
+ "https://github.com/$USERNAME/$repo_name")
167
+
168
+ if [ "$REPO_CODE" = "200" ]; then
169
+ echo "āœ… Accessible (HTTP 200)"
170
+
171
+ # Try to get file list
172
+ FILE_LIST=$(curl -s \
173
+ -H "Cookie: $COOKIES" \
174
+ -H "User-Agent: Mozilla/5.0" \
175
+ "https://github.com/$USERNAME/$repo_name" | grep -o 'js-navigation-open Link--primary' | wc -l | xargs)
176
+
177
+ if [ "$FILE_LIST" -gt 0 ]; then
178
+ echo " └─ āœ… Can see $FILE_LIST files/folders"
179
+ fi
180
+ return 0
181
+ elif [ "$REPO_CODE" = "404" ]; then
182
+ echo "āŒ Not found or no access (HTTP 404)"
183
+ return 1
184
+ else
185
+ echo "āŒ Cannot access (HTTP $REPO_CODE)"
186
+ return 1
187
+ fi
188
+ }
189
+
190
+ # Test some common private repo names (you can modify these)
191
+ echo "Testing potential private repositories..."
192
+ for repo in "private" "personal" "dotfiles" "config" "secrets" "private-notes"; do
193
+ test_private_repo "$repo"
194
+ done
195
+
196
+ echo ""
197
+ echo "Testing raw file access..."
198
+ echo "─────────────────────"
199
+
200
+ # Try to access a raw file from a public repo (should work)
201
+ echo -n "• Public repo raw file: "
202
+ RAW_PUBLIC=$(curl -s -o /dev/null -w "%{http_code}" \
203
+ -H "Cookie: $COOKIES" \
204
+ -H "User-Agent: Mozilla/5.0" \
205
+ "https://raw.githubusercontent.com/$USERNAME/get-cookie/main/README.md")
206
+
207
+ if [ "$RAW_PUBLIC" = "200" ]; then
208
+ echo "āœ… Can access"
209
+ else
210
+ echo "āŒ Cannot access (HTTP $RAW_PUBLIC)"
211
+ fi
212
+
213
+ echo ""
214
+ echo "Advanced: Testing GitHub's auth state..."
215
+ echo "────────────────────────────────────────"
216
+
217
+ # Check the actual auth state from GitHub's perspective
218
+ AUTH_CHECK=$(curl -s \
219
+ -H "Cookie: $COOKIES" \
220
+ -H "User-Agent: Mozilla/5.0" \
221
+ -H "Accept: application/json" \
222
+ "https://github.com/users/$USERNAME/hovercard" | jq -r '.message // "authenticated"')
223
+
224
+ if [ "$AUTH_CHECK" = "authenticated" ]; then
225
+ echo "āœ… GitHub recognizes our session as authenticated"
226
+ else
227
+ echo "āš ļø GitHub response: $AUTH_CHECK"
228
+ fi
229
+
230
+ echo ""
231
+ echo "Summary"
232
+ echo "======="
233
+ echo ""
234
+ echo "šŸ“ What we learned:"
235
+ echo "• Browser cookies work for GitHub web pages (not API)"
236
+ echo "• Can access authenticated pages like settings"
237
+ echo "• Can view private repositories through the web interface"
238
+ echo "• Cannot use these cookies for the REST API (needs tokens)"
239
+ echo ""
240
+ echo "šŸ’” To actually work with private repos via CLI:"
241
+ echo "• Use GitHub CLI: gh auth login"
242
+ echo "• Or create a Personal Access Token"
243
+ echo "• Browser cookies are mainly useful for web scraping"
244
+ echo ""
245
+ echo "āœ… Test complete!"
@@ -0,0 +1,136 @@
1
+ #!/bin/bash
2
+
3
+ # Test GitHub authentication with improved expired cookie filtering
4
+ echo "šŸ” Testing GitHub Authentication with Improved Cookie Filtering"
5
+ echo "=============================================================="
6
+ echo ""
7
+
8
+ # Method 1: Using --url and --render (the recommended pattern)
9
+ echo "Method 1: Using --url and --render (default filtering)"
10
+ echo "──────────────────────────────────────────────────────"
11
+
12
+ # Get cookies for GitHub settings
13
+ COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
14
+ echo "Cookie string length: $(echo "$COOKIES" | wc -c) characters"
15
+
16
+ # Test authentication
17
+ echo -n "Testing authentication: "
18
+ RESPONSE=$(curl -s -L \
19
+ -H "Cookie: $COOKIES" \
20
+ -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
21
+ -H "Accept: text/html,application/xhtml+xml" \
22
+ "https://github.com/settings/profile")
23
+
24
+ if echo "$RESPONSE" | grep -q "Sign in to GitHub"; then
25
+ echo "āŒ Not authenticated (redirected to login)"
26
+ elif echo "$RESPONSE" | grep -q "Your profile"; then
27
+ echo "āœ… Authenticated! (settings page accessed)"
28
+ else
29
+ TITLE=$(echo "$RESPONSE" | grep -o "<title>[^<]*</title>" | head -1)
30
+ echo "ā„¹ļø Page title: $TITLE"
31
+ fi
32
+ echo ""
33
+
34
+ # Method 2: With --include-expired to see the difference
35
+ echo "Method 2: With --include-expired flag"
36
+ echo "─────────────────────────────────────"
37
+
38
+ COOKIES_WITH_EXPIRED=$(get-cookie --url https://github.com/settings/profile --render --include-expired 2>/dev/null)
39
+ echo "Cookie string length: $(echo "$COOKIES_WITH_EXPIRED" | wc -c) characters"
40
+
41
+ # Compare cookie counts
42
+ DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
43
+ EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
44
+
45
+ echo "Cookies comparison:"
46
+ echo " • Without --include-expired: $DEFAULT_COUNT cookies"
47
+ echo " • With --include-expired: $EXPIRED_COUNT cookies"
48
+
49
+ if [ "$EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
50
+ DIFF=$((EXPIRED_COUNT - DEFAULT_COUNT))
51
+ echo " • āœ… Filtered out $DIFF expired cookies"
52
+ else
53
+ echo " • ā„¹ļø No expired cookies to filter (all cookies are valid)"
54
+ fi
55
+ echo ""
56
+
57
+ # Method 3: Smart filtering for valid session cookies
58
+ echo "Method 3: JSON filtering for valid cookies"
59
+ echo "──────────────────────────────────────────"
60
+
61
+ # Get valid session cookie (filter by length and expiry)
62
+ VALID_SESSION=$(get-cookie --url https://github.com --output json 2>/dev/null | \
63
+ jq -r '.[] | select(.name == "user_session" and (.value | length) > 20) | .value' | \
64
+ head -1)
65
+
66
+ if [ -n "$VALID_SESSION" ]; then
67
+ echo "āœ… Found valid session cookie: ${VALID_SESSION:0:20}... (${#VALID_SESSION} chars)"
68
+
69
+ # Build cookie header
70
+ COOKIE_HEADER="user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION"
71
+
72
+ # Test authentication
73
+ echo -n "Testing with filtered session: "
74
+ AUTH_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
75
+ -H "Cookie: $COOKIE_HEADER" \
76
+ -H "User-Agent: Mozilla/5.0" \
77
+ "https://github.com/settings/profile")
78
+
79
+ if [ "$AUTH_CODE" = "200" ]; then
80
+ echo "āœ… Authenticated (HTTP 200)"
81
+ else
82
+ echo "āŒ Not authenticated (HTTP $AUTH_CODE)"
83
+ fi
84
+ else
85
+ echo "āŒ No valid session cookie found"
86
+ fi
87
+ echo ""
88
+
89
+ # Final test: Access private content
90
+ echo "Final Test: Accessing Private Repository List"
91
+ echo "─────────────────────────────────────────────"
92
+
93
+ # Try to get username from cookies
94
+ USERNAME=$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)
95
+
96
+ if [ -n "$USERNAME" ]; then
97
+ echo "Username detected: $USERNAME"
98
+
99
+ # Get repository list with authentication
100
+ REPOS_HTML=$(curl -s -L \
101
+ -H "Cookie: $(get-cookie --url https://github.com/$USERNAME --render)" \
102
+ -H "User-Agent: Mozilla/5.0" \
103
+ "https://github.com/$USERNAME?tab=repositories")
104
+
105
+ # Count visible repositories
106
+ PUBLIC_COUNT=$(echo "$REPOS_HTML" | grep -o '>Public<' | wc -l | xargs)
107
+ PRIVATE_COUNT=$(echo "$REPOS_HTML" | grep -o '>Private<' | wc -l | xargs)
108
+
109
+ echo "Repository visibility:"
110
+ echo " • Public repositories: $PUBLIC_COUNT"
111
+ echo " • Private repositories: $PRIVATE_COUNT"
112
+
113
+ if [ "$PRIVATE_COUNT" -gt 0 ]; then
114
+ echo " • āœ… Can see private repositories!"
115
+ else
116
+ echo " • āš ļø No private repositories visible"
117
+ fi
118
+ else
119
+ echo "āŒ Could not detect username from cookies"
120
+ fi
121
+ echo ""
122
+
123
+ echo "šŸ’” Summary:"
124
+ echo "─────────"
125
+ echo "• Default behavior filters expired cookies for better success"
126
+ echo "• Use --include-expired to include all cookies (debugging)"
127
+ echo "• For best results: get-cookie --url <URL> --render"
128
+ echo "• Some browsers may store invalid cookies that need filtering"
129
+ echo ""
130
+
131
+ # Check if the feature is making a difference
132
+ if [ "$DEFAULT_COUNT" -eq "$EXPIRED_COUNT" ]; then
133
+ echo "ā„¹ļø Note: Currently all cookies are valid (no expired cookies found)"
134
+ else
135
+ echo "āœ… Expired cookie filtering is improving authentication!"
136
+ fi
@@ -0,0 +1,117 @@
1
+ #!/bin/bash
2
+
3
+ # Working example: Using get-cookie with curl for web scraping
4
+ echo "🌐 Web Scraping with get-cookie + curl"
5
+ echo "======================================="
6
+
7
+ # Example 1: Check if logged into GitHub (web, not API)
8
+ echo -e "\n1ļøāƒ£ Checking GitHub login status (web)..."
9
+ GITHUB_COOKIES=$(get-cookie % github.com --render 2>/dev/null | head -1)
10
+
11
+ if [ -n "$GITHUB_COOKIES" ]; then
12
+ # Access the settings page which requires authentication
13
+ RESPONSE=$(curl -s -L \
14
+ -H "Cookie: $GITHUB_COOKIES" \
15
+ -H "User-Agent: Mozilla/5.0" \
16
+ "https://github.com/settings/profile" | grep -o '<input.*name="user\[profile_name\]".*value="[^"]*"' | sed 's/.*value="\([^"]*\)".*/\1/')
17
+
18
+ if [ -n "$RESPONSE" ]; then
19
+ echo " āœ… Successfully accessed GitHub settings"
20
+ echo " Profile name field found: $RESPONSE"
21
+ else
22
+ echo " āš ļø Could not access settings (may need more cookies)"
23
+ fi
24
+ else
25
+ echo " āŒ No GitHub cookies found"
26
+ fi
27
+
28
+ # Example 2: Download a file that requires login
29
+ echo -e "\n2ļøāƒ£ Example: Download private content..."
30
+ echo " Command to download a private gist:"
31
+ echo " curl -H \"Cookie: \$(get-cookie % github.com --render)\" -o gist.txt https://gist.github.com/username/gist_id/raw"
32
+
33
+ # Example 3: Check login status on various sites
34
+ echo -e "\n3ļøāƒ£ Checking login status on popular sites..."
35
+
36
+ check_site_login() {
37
+ local domain=$1
38
+ local check_url=$2
39
+ local check_string=$3
40
+
41
+ echo -n " $domain: "
42
+
43
+ COOKIES=$(get-cookie % "$domain" --render 2>/dev/null | head -1)
44
+ if [ -z "$COOKIES" ]; then
45
+ echo "No cookies found"
46
+ return
47
+ fi
48
+
49
+ # Try to access a page that requires login
50
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
51
+ -H "Cookie: $COOKIES" \
52
+ -H "User-Agent: Mozilla/5.0" \
53
+ "$check_url")
54
+
55
+ if [ "$HTTP_CODE" = "200" ]; then
56
+ echo "āœ… Logged in (HTTP 200)"
57
+ elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
58
+ echo "āš ļø Redirected (HTTP $HTTP_CODE) - possibly logged out"
59
+ else
60
+ echo "āŒ Not accessible (HTTP $HTTP_CODE)"
61
+ fi
62
+ }
63
+
64
+ check_site_login "github.com" "https://github.com/settings/profile" "Settings"
65
+ check_site_login "stackoverflow.com" "https://stackoverflow.com/users/edit/current" "Edit Profile"
66
+ check_site_login "linkedin.com" "https://www.linkedin.com/in/me/" "Profile"
67
+
68
+ # Example 4: Practical scraping example
69
+ echo -e "\n4ļøāƒ£ Practical example: Get your GitHub stats..."
70
+ if [ -n "$GITHUB_COOKIES" ]; then
71
+ # Get the user's contribution graph data
72
+ USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2)
73
+ if [ -n "$USERNAME" ]; then
74
+ echo " Fetching contribution data for: $USERNAME"
75
+
76
+ # This would normally require being logged in to see private contributions
77
+ CONTRIBUTIONS=$(curl -s \
78
+ -H "Cookie: $GITHUB_COOKIES" \
79
+ -H "User-Agent: Mozilla/5.0" \
80
+ "https://github.com/$USERNAME" | grep -o 'data-count="[0-9]*"' | head -7 | sed 's/data-count="\([0-9]*\)"/\1/')
81
+
82
+ if [ -n "$CONTRIBUTIONS" ]; then
83
+ echo " Recent contribution counts:"
84
+ echo "$CONTRIBUTIONS" | head -7 | while read count; do
85
+ echo " • $count contributions"
86
+ done
87
+ fi
88
+ fi
89
+ fi
90
+
91
+ # Example 5: Advanced - Using with jq for JSON APIs that accept cookies
92
+ echo -e "\n5ļøāƒ£ One-liner examples for common tasks:"
93
+ echo "────────────────────────────────────────"
94
+ cat << 'EOF'
95
+ # Download all cookies as JSON for backup:
96
+ get-cookie % github.com --output json > github-cookies-backup.json
97
+
98
+ # Use with wget instead of curl:
99
+ wget --no-cookies --header "Cookie: $(get-cookie % example.com --render)" https://example.com/file
100
+
101
+ # Chain multiple domains:
102
+ (get-cookie % site1.com --render; get-cookie % site2.com --render) | curl -H "Cookie: $(cat)" https://api.example.com
103
+
104
+ # Use with httpie (more user-friendly than curl):
105
+ http GET https://example.com Cookie:"$(get-cookie % example.com --render)"
106
+
107
+ # Quick login check:
108
+ get-cookie logged_in github.com --render && echo "āœ… Logged in" || echo "āŒ Not logged in"
109
+ EOF
110
+
111
+ echo -e "\nšŸ“ Notes:"
112
+ echo "• The --render flag outputs: name1=value1; name2=value2"
113
+ echo "• Perfect for curl's Cookie header"
114
+ echo "• Works with any site that uses cookie authentication"
115
+ echo "• Remember: GitHub's API uses tokens, not cookies"
116
+
117
+ echo -e "\nāœ… Examples complete!"
@@ -0,0 +1,87 @@
1
+ #!/bin/bash
2
+
3
+ # Working GitHub authentication with get-cookie
4
+ # This shows how to handle real-world cookie issues
5
+
6
+ echo "šŸ” Working GitHub Authentication with get-cookie"
7
+ echo "==============================================="
8
+ echo ""
9
+
10
+ # Method 1: Using --url and --render with validation
11
+ echo "Method 1: Smart cookie filtering"
12
+ echo "────────────────────────────────"
13
+
14
+ # Get cookies and filter out invalid ones (too short)
15
+ COOKIES=$(get-cookie --url https://github.com/settings/profile --output json 2>/dev/null | \
16
+ jq -r '.[] | select(.name == "user_session" and (.value | length) > 10) | "\(.name)=\(.value)"' | \
17
+ head -1)
18
+
19
+ if [ -n "$COOKIES" ]; then
20
+ echo "āœ… Found valid session cookie"
21
+
22
+ # Add the same-site cookie
23
+ COOKIES="$COOKIES; __Host-user_session_same_site=${COOKIES#*=}"
24
+
25
+ echo "Testing authentication..."
26
+ TITLE=$(curl -s -L \
27
+ -H "Cookie: $COOKIES" \
28
+ -H "User-Agent: Mozilla/5.0" \
29
+ "https://github.com/settings/profile" | \
30
+ grep -o "<title>[^<]*</title>" | head -1)
31
+
32
+ if echo "$TITLE" | grep -q "Your profile"; then
33
+ echo "āœ… Successfully authenticated!"
34
+ else
35
+ echo "āŒ Not authenticated: $TITLE"
36
+ fi
37
+ else
38
+ echo "āŒ No valid session cookies found"
39
+ fi
40
+
41
+ echo ""
42
+ echo "Method 2: Direct approach with validation"
43
+ echo "─────────────────────────────────────────"
44
+
45
+ # Function to get valid cookies only
46
+ get_valid_cookie() {
47
+ local cookie_name=$1
48
+ local domain=$2
49
+ local min_length=${3:-10} # Minimum valid length
50
+
51
+ get-cookie "$cookie_name" "$domain" --output json 2>/dev/null | \
52
+ jq -r --arg min "$min_length" \
53
+ '.[] | select(.value | length > ($min | tonumber)) | .value' | \
54
+ head -1
55
+ }
56
+
57
+ # Get a valid session
58
+ VALID_SESSION=$(get_valid_cookie "user_session" "github.com" 20)
59
+
60
+ if [ -n "$VALID_SESSION" ]; then
61
+ echo "āœ… Found valid session: ${VALID_SESSION:0:20}... (truncated)"
62
+
63
+ # Test with curl
64
+ curl -s -I \
65
+ -H "Cookie: user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION" \
66
+ -H "User-Agent: Mozilla/5.0" \
67
+ "https://github.com/settings/profile" | head -1
68
+ else
69
+ echo "āŒ No valid session found"
70
+ fi
71
+
72
+ echo ""
73
+ echo "Method 3: The Ultimate One-Liner"
74
+ echo "────────────────────────────────"
75
+ echo ""
76
+ echo "# Get valid cookies and access private content:"
77
+ echo 'curl -H "Cookie: $(get-cookie --url https://github.com --output json | jq -r '"'"'.[] | select(.name == "user_session" and (.value | length) > 20) | "\(.name)=\(.value)"'"'"' | head -1)" https://github.com/settings/profile'
78
+ echo ""
79
+
80
+ echo "šŸ’” Key Insights:"
81
+ echo "──────────────"
82
+ echo "• Some browsers store truncated/invalid cookies"
83
+ echo "• Filter cookies by value length for validity"
84
+ echo "• GitHub needs both user_session and __Host-user_session_same_site"
85
+ echo "• The new --include-expired flag helps debug cookie issues"
86
+ echo ""
87
+ echo "āœ… With proper filtering, get-cookie works perfectly for authentication!"