@mherod/get-cookie 4.4.3 → 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.
- package/README.md +21 -3
- package/dist/bun.cjs +77 -0
- package/dist/bun.cjs.map +1 -0
- package/dist/bun.d.cts +3 -0
- package/dist/bun.d.ts +3 -0
- package/dist/bun.js +77 -0
- package/dist/bun.js.map +1 -0
- package/dist/cli.cjs +14 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -38
- package/dist/index.d.ts +98 -38
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +77 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +3 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.js +77 -0
- package/dist/node.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -14
- package/.claude/settings.local.json +0 -3
- package/.dependency-cruiser.js +0 -277
- package/.env.example +0 -5
- package/.husky/commit-msg +0 -19
- package/.husky/pre-commit +0 -29
- package/.husky/pre-push +0 -21
- package/.idea/codeStyles/Project.xml +0 -59
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/get-cookie.iml +0 -13
- package/.idea/git_toolbox_prj.xml +0 -15
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -9
- package/.idea/runConfigurations/build.xml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.nvmrc +0 -1
- package/biome.json +0 -117
- package/commitlint.config.js +0 -12
- package/eslint.config.js +0 -255
- package/examples/README.md +0 -71
- package/examples/advanced-usage.ts +0 -56
- package/examples/auth-tokens.ts +0 -143
- package/examples/basic-usage.ts +0 -43
- package/examples/cli-examples.sh +0 -51
- package/examples/comprehensive-demo.ts +0 -202
- package/examples/curl-integration.sh +0 -311
- package/examples/features-demo.sh +0 -260
- package/examples/github-auth.sh +0 -295
- package/examples/quick-start.sh +0 -115
- package/jest.setup.js +0 -34
- package/tsconfig.build.json +0 -9
- package/tsconfig.cli.json +0 -16
- package/tsconfig.tsup.json +0 -12
- package/tsup.cli.ts +0 -59
- package/tsup.lib.ts +0 -46
- package/typedoc.json +0 -17
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# ============================================================================
|
|
4
|
-
# get-cookie CLI Features Demonstration
|
|
5
|
-
# ============================================================================
|
|
6
|
-
# Comprehensive guide to all advanced CLI features including profile
|
|
7
|
-
# selection, cookie deduplication, expired filtering, and browser-specific
|
|
8
|
-
# extraction.
|
|
9
|
-
# ============================================================================
|
|
10
|
-
|
|
11
|
-
echo "✨ get-cookie CLI Features Demonstration"
|
|
12
|
-
echo "========================================"
|
|
13
|
-
echo ""
|
|
14
|
-
|
|
15
|
-
# ============================================================================
|
|
16
|
-
# Feature 1: Profile Listing and Selection
|
|
17
|
-
# ============================================================================
|
|
18
|
-
echo "1️⃣ Profile Listing and Selection"
|
|
19
|
-
echo "─────────────────────────────────"
|
|
20
|
-
echo ""
|
|
21
|
-
|
|
22
|
-
echo "The --list-profiles option helps you discover available browser profiles:"
|
|
23
|
-
echo ""
|
|
24
|
-
echo "Command: get-cookie --browser chrome --list-profiles"
|
|
25
|
-
echo ""
|
|
26
|
-
|
|
27
|
-
if get-cookie --browser chrome --list-profiles 2>/dev/null | head -5 | grep -q "."; then
|
|
28
|
-
echo "Available Chrome profiles:"
|
|
29
|
-
get-cookie --browser chrome --list-profiles 2>/dev/null | head -5
|
|
30
|
-
echo ""
|
|
31
|
-
|
|
32
|
-
echo "Step 1: List available profiles"
|
|
33
|
-
echo " get-cookie --browser chrome --list-profiles"
|
|
34
|
-
echo ""
|
|
35
|
-
echo "Step 2: Use a specific profile name from the list"
|
|
36
|
-
echo ' get-cookie --url https://github.com --browser chrome --profile "Profile Name" --render'
|
|
37
|
-
echo ""
|
|
38
|
-
|
|
39
|
-
# Test profile-specific extraction
|
|
40
|
-
PROFILE_NAME=$(get-cookie --browser chrome --list-profiles 2>/dev/null | head -1 | cut -d':' -f1 | xargs)
|
|
41
|
-
if [ -n "$PROFILE_NAME" ]; then
|
|
42
|
-
echo "Example: Getting cookies from '$PROFILE_NAME' profile:"
|
|
43
|
-
SESSION=$(get-cookie user_session github.com --browser chrome --profile "$PROFILE_NAME" --render 2>/dev/null)
|
|
44
|
-
if [ -n "$SESSION" ]; then
|
|
45
|
-
VALUE=$(echo "$SESSION" | cut -d'=' -f2)
|
|
46
|
-
echo " user_session=${VALUE:0:20}... (${#VALUE} chars)"
|
|
47
|
-
else
|
|
48
|
-
echo " No user_session cookie found in this profile"
|
|
49
|
-
fi
|
|
50
|
-
fi
|
|
51
|
-
else
|
|
52
|
-
echo "ℹ️ No Chrome profiles found (or Chrome not installed)"
|
|
53
|
-
echo ""
|
|
54
|
-
echo "Supported browsers with profile support:"
|
|
55
|
-
echo " • chrome - Google Chrome"
|
|
56
|
-
echo " • edge - Microsoft Edge"
|
|
57
|
-
echo " • arc - Arc Browser"
|
|
58
|
-
echo " • opera - Opera"
|
|
59
|
-
echo " • opera-gx - Opera GX"
|
|
60
|
-
fi
|
|
61
|
-
echo ""
|
|
62
|
-
|
|
63
|
-
# ============================================================================
|
|
64
|
-
# Feature 2: Cookie Deduplication
|
|
65
|
-
# ============================================================================
|
|
66
|
-
echo "2️⃣ Cookie Deduplication"
|
|
67
|
-
echo "───────────────────────"
|
|
68
|
-
echo ""
|
|
69
|
-
|
|
70
|
-
echo "Chrome can store duplicate cookies from different profiles."
|
|
71
|
-
echo "get-cookie automatically deduplicates by default, keeping the most valid one."
|
|
72
|
-
echo ""
|
|
73
|
-
|
|
74
|
-
echo "The Problem: Chrome Duplicate Cookies"
|
|
75
|
-
echo "─────────────────────────────────────"
|
|
76
|
-
echo "Chrome may store duplicate cookies from different profiles."
|
|
77
|
-
echo "Let's see what happens with --include-all (old behavior):"
|
|
78
|
-
echo ""
|
|
79
|
-
|
|
80
|
-
echo "Command: get-cookie user_session github.com --browser chrome --output json --include-all"
|
|
81
|
-
DUPLICATE_COUNT=$(get-cookie user_session github.com --browser chrome --output json --include-all 2>/dev/null | jq 'length // 0')
|
|
82
|
-
echo " Found $DUPLICATE_COUNT duplicate user_session cookies"
|
|
83
|
-
echo ""
|
|
84
|
-
|
|
85
|
-
echo "The Solution: Automatic Deduplication (Default)"
|
|
86
|
-
echo "───────────────────────────────────────────────"
|
|
87
|
-
echo "By default, get-cookie now keeps only the most valid cookie:"
|
|
88
|
-
echo ""
|
|
89
|
-
|
|
90
|
-
echo "Command: get-cookie user_session github.com --browser chrome --output json"
|
|
91
|
-
DEDUP_COUNT=$(get-cookie user_session github.com --browser chrome --output json 2>/dev/null | jq 'length // 0')
|
|
92
|
-
echo " Found $DEDUP_COUNT deduplicated user_session cookies"
|
|
93
|
-
echo ""
|
|
94
|
-
|
|
95
|
-
if [ "$DUPLICATE_COUNT" -gt "$DEDUP_COUNT" ]; then
|
|
96
|
-
REMOVED=$((DUPLICATE_COUNT - DEDUP_COUNT))
|
|
97
|
-
echo " ✅ Removed $REMOVED duplicate cookies"
|
|
98
|
-
else
|
|
99
|
-
echo " ℹ️ No duplicates found (or same count)"
|
|
100
|
-
fi
|
|
101
|
-
echo ""
|
|
102
|
-
|
|
103
|
-
echo "Impact on --render Output:"
|
|
104
|
-
echo "─────────────────────────"
|
|
105
|
-
RENDER_ALL=$(get-cookie user_session github.com --browser chrome --render --include-all 2>/dev/null)
|
|
106
|
-
RENDER_DEDUP=$(get-cookie user_session github.com --browser chrome --render 2>/dev/null)
|
|
107
|
-
|
|
108
|
-
echo "With --include-all (all duplicates):"
|
|
109
|
-
echo " Length: $(echo "$RENDER_ALL" | wc -c) chars"
|
|
110
|
-
echo ""
|
|
111
|
-
echo "Default (deduplicated):"
|
|
112
|
-
echo " Length: $(echo "$RENDER_DEDUP" | wc -c) chars"
|
|
113
|
-
echo ""
|
|
114
|
-
|
|
115
|
-
echo "💡 The deduplication ensures curl gets the valid cookie:"
|
|
116
|
-
echo ' curl -H "Cookie: $(get-cookie --url <URL> --browser chrome --render)" <URL>'
|
|
117
|
-
echo ""
|
|
118
|
-
|
|
119
|
-
# ============================================================================
|
|
120
|
-
# Feature 3: Expired Cookie Filtering
|
|
121
|
-
# ============================================================================
|
|
122
|
-
echo "3️⃣ Expired Cookie Filtering"
|
|
123
|
-
echo "───────────────────────────"
|
|
124
|
-
echo ""
|
|
125
|
-
|
|
126
|
-
echo "By default, get-cookie filters out expired cookies for better authentication success."
|
|
127
|
-
echo ""
|
|
128
|
-
|
|
129
|
-
echo "Default behavior (filters expired cookies):"
|
|
130
|
-
DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length // 0')
|
|
131
|
-
echo " Cookies returned: $DEFAULT_COUNT"
|
|
132
|
-
echo ""
|
|
133
|
-
|
|
134
|
-
echo "With --include-expired flag:"
|
|
135
|
-
WITH_EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length // 0')
|
|
136
|
-
echo " Cookies returned: $WITH_EXPIRED_COUNT"
|
|
137
|
-
echo ""
|
|
138
|
-
|
|
139
|
-
if [ "$WITH_EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
|
|
140
|
-
DIFF=$((WITH_EXPIRED_COUNT - DEFAULT_COUNT))
|
|
141
|
-
echo " ✅ Filtering is working! Removed $DIFF expired cookies"
|
|
142
|
-
else
|
|
143
|
-
echo " ℹ️ No expired cookies found (or same count)"
|
|
144
|
-
fi
|
|
145
|
-
echo ""
|
|
146
|
-
|
|
147
|
-
echo "Sample cookies with expiry info:"
|
|
148
|
-
echo "───────────────────────────────"
|
|
149
|
-
echo "Default (non-expired only):"
|
|
150
|
-
get-cookie --url https://github.com --output json 2>/dev/null | \
|
|
151
|
-
jq -r '.[:3] | .[] | " • \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"' 2>/dev/null
|
|
152
|
-
echo ""
|
|
153
|
-
|
|
154
|
-
echo "With expired included:"
|
|
155
|
-
get-cookie --url https://github.com --output json --include-expired 2>/dev/null | \
|
|
156
|
-
jq -r '.[:3] | .[] | " • \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"' 2>/dev/null
|
|
157
|
-
echo ""
|
|
158
|
-
|
|
159
|
-
# ============================================================================
|
|
160
|
-
# Feature 4: Browser-Specific Extraction
|
|
161
|
-
# ============================================================================
|
|
162
|
-
echo "4️⃣ Browser-Specific Extraction"
|
|
163
|
-
echo "──────────────────────────────"
|
|
164
|
-
echo ""
|
|
165
|
-
|
|
166
|
-
echo "Target a specific browser with --browser flag:"
|
|
167
|
-
echo ""
|
|
168
|
-
echo " get-cookie --url <URL> --browser chrome --render"
|
|
169
|
-
echo " get-cookie --url <URL> --browser firefox --render"
|
|
170
|
-
echo " get-cookie --url <URL> --browser safari --render"
|
|
171
|
-
echo ""
|
|
172
|
-
|
|
173
|
-
echo "Testing browser-specific extraction:"
|
|
174
|
-
for browser in chrome firefox safari; do
|
|
175
|
-
COUNT=$(get-cookie --url https://github.com --browser "$browser" --output json 2>/dev/null | jq 'length // 0')
|
|
176
|
-
if [ "$COUNT" -gt 0 ]; then
|
|
177
|
-
echo " • $browser: $COUNT cookies found"
|
|
178
|
-
else
|
|
179
|
-
echo " • $browser: No cookies found (or browser not installed)"
|
|
180
|
-
fi
|
|
181
|
-
done
|
|
182
|
-
echo ""
|
|
183
|
-
|
|
184
|
-
# ============================================================================
|
|
185
|
-
# Feature 5: Combining Features
|
|
186
|
-
# ============================================================================
|
|
187
|
-
echo "5️⃣ Combining Features"
|
|
188
|
-
echo "────────────────────"
|
|
189
|
-
echo ""
|
|
190
|
-
|
|
191
|
-
echo "You can combine multiple features for precise control:"
|
|
192
|
-
echo ""
|
|
193
|
-
echo "Example 1: Profile + Browser + Deduplication"
|
|
194
|
-
echo ' get-cookie --url <URL> --browser chrome --profile "Work" --render'
|
|
195
|
-
echo ""
|
|
196
|
-
echo "Example 2: Include Expired + All Duplicates (for debugging)"
|
|
197
|
-
echo ' get-cookie --url <URL> --output json --include-expired --include-all'
|
|
198
|
-
echo ""
|
|
199
|
-
echo "Example 3: Browser + JSON Output + Filtering"
|
|
200
|
-
echo ' get-cookie --url <URL> --browser chrome --output json | \'
|
|
201
|
-
echo ' jq '"'"'.[] | select(.name == "user_session" and (.value | length) > 20)'"'"
|
|
202
|
-
echo ""
|
|
203
|
-
|
|
204
|
-
# ============================================================================
|
|
205
|
-
# Feature 6: Practical Workflow
|
|
206
|
-
# ============================================================================
|
|
207
|
-
echo "6️⃣ Practical Workflow"
|
|
208
|
-
echo "────────────────────"
|
|
209
|
-
echo ""
|
|
210
|
-
|
|
211
|
-
cat << 'EOF'
|
|
212
|
-
# Complete workflow for authenticated requests:
|
|
213
|
-
|
|
214
|
-
# 1. Check which profiles are available
|
|
215
|
-
get-cookie --browser chrome --list-profiles
|
|
216
|
-
|
|
217
|
-
# 2. Choose the profile with the right session
|
|
218
|
-
# (e.g., "Work" for company repos, "Personal" for personal)
|
|
219
|
-
|
|
220
|
-
# 3. Extract cookies from that specific profile
|
|
221
|
-
COOKIES=$(get-cookie --url https://github.com \
|
|
222
|
-
--browser chrome \
|
|
223
|
-
--profile "Work" \
|
|
224
|
-
--render)
|
|
225
|
-
|
|
226
|
-
# 4. Use with curl for authenticated requests
|
|
227
|
-
curl -H "Cookie: $COOKIES" https://github.com/company/private-repo
|
|
228
|
-
EOF
|
|
229
|
-
echo ""
|
|
230
|
-
|
|
231
|
-
# ============================================================================
|
|
232
|
-
# Summary
|
|
233
|
-
# ============================================================================
|
|
234
|
-
echo "📊 Feature Summary"
|
|
235
|
-
echo "─────────────────"
|
|
236
|
-
echo ""
|
|
237
|
-
|
|
238
|
-
TOTAL_ALL=$(get-cookie % github.com --browser chrome --output json --include-all 2>/dev/null | jq 'length // 0')
|
|
239
|
-
TOTAL_DEDUP=$(get-cookie % github.com --browser chrome --output json 2>/dev/null | jq 'length // 0')
|
|
240
|
-
REMOVED=$((TOTAL_ALL - TOTAL_DEDUP))
|
|
241
|
-
|
|
242
|
-
echo "Chrome cookies for github.com:"
|
|
243
|
-
echo " • With --include-all: $TOTAL_ALL cookies"
|
|
244
|
-
echo " • Default (deduplicated): $TOTAL_DEDUP cookies"
|
|
245
|
-
if [ "$REMOVED" -gt 0 ]; then
|
|
246
|
-
echo " • Duplicates removed: $REMOVED"
|
|
247
|
-
fi
|
|
248
|
-
echo ""
|
|
249
|
-
|
|
250
|
-
echo "💡 Key Points:"
|
|
251
|
-
echo "────────────"
|
|
252
|
-
echo "• Deduplication is ON by default (keeps longest/newest cookie)"
|
|
253
|
-
echo "• Expired cookies are filtered by default (use --include-expired to see all)"
|
|
254
|
-
echo "• Use --include-all to see all duplicates (for debugging)"
|
|
255
|
-
echo "• Profile selection avoids conflicts between browser profiles"
|
|
256
|
-
echo "• Browser-specific extraction ensures you get cookies from the right source"
|
|
257
|
-
echo ""
|
|
258
|
-
|
|
259
|
-
echo "✅ Features demonstration complete!"
|
|
260
|
-
|
package/examples/github-auth.sh
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# ============================================================================
|
|
4
|
-
# GitHub Authentication with get-cookie
|
|
5
|
-
# ============================================================================
|
|
6
|
-
# Complete guide for authenticating with GitHub using browser cookies.
|
|
7
|
-
# Covers web authentication, private repository access, and API limitations.
|
|
8
|
-
# ============================================================================
|
|
9
|
-
|
|
10
|
-
echo "🔐 GitHub Authentication with get-cookie"
|
|
11
|
-
echo "========================================"
|
|
12
|
-
echo ""
|
|
13
|
-
|
|
14
|
-
# ============================================================================
|
|
15
|
-
# Method 1: Smart Cookie Filtering (Recommended)
|
|
16
|
-
# ============================================================================
|
|
17
|
-
echo "1️⃣ Method 1: Smart Cookie Filtering"
|
|
18
|
-
echo "───────────────────────────────────"
|
|
19
|
-
|
|
20
|
-
echo "Using --url and --render with automatic filtering:"
|
|
21
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
|
|
22
|
-
echo "Cookie string length: $(echo "$COOKIES" | wc -c) characters"
|
|
23
|
-
|
|
24
|
-
# Test authentication
|
|
25
|
-
echo -n "Testing authentication: "
|
|
26
|
-
RESPONSE=$(curl -s -L \
|
|
27
|
-
-H "Cookie: $COOKIES" \
|
|
28
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
|
|
29
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
30
|
-
"https://github.com/settings/profile")
|
|
31
|
-
|
|
32
|
-
if echo "$RESPONSE" | grep -q "Sign in to GitHub"; then
|
|
33
|
-
echo "❌ Not authenticated (redirected to login)"
|
|
34
|
-
elif echo "$RESPONSE" | grep -q "Your profile"; then
|
|
35
|
-
echo "✅ Authenticated! (settings page accessed)"
|
|
36
|
-
else
|
|
37
|
-
TITLE=$(echo "$RESPONSE" | grep -o "<title>[^<]*</title>" | head -1)
|
|
38
|
-
echo "ℹ️ Page title: $TITLE"
|
|
39
|
-
fi
|
|
40
|
-
echo ""
|
|
41
|
-
|
|
42
|
-
# ============================================================================
|
|
43
|
-
# Method 2: JSON Filtering for Valid Session Cookies
|
|
44
|
-
# ============================================================================
|
|
45
|
-
echo "2️⃣ Method 2: JSON Filtering for Valid Cookies"
|
|
46
|
-
echo "─────────────────────────────────────────────"
|
|
47
|
-
|
|
48
|
-
# Function to get valid cookies only
|
|
49
|
-
get_valid_cookie() {
|
|
50
|
-
local cookie_name=$1
|
|
51
|
-
local domain=$2
|
|
52
|
-
local min_length=${3:-10} # Minimum valid length
|
|
53
|
-
|
|
54
|
-
get-cookie "$cookie_name" "$domain" --output json 2>/dev/null | \
|
|
55
|
-
jq -r --arg min "$min_length" \
|
|
56
|
-
'.[] | select(.value | length > ($min | tonumber)) | .value' | \
|
|
57
|
-
head -1
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
# Get a valid session
|
|
61
|
-
VALID_SESSION=$(get_valid_cookie "user_session" "github.com" 20)
|
|
62
|
-
|
|
63
|
-
if [ -n "$VALID_SESSION" ]; then
|
|
64
|
-
echo "✅ Found valid session: ${VALID_SESSION:0:20}... (${#VALID_SESSION} chars)"
|
|
65
|
-
|
|
66
|
-
# Build cookie header with same-site cookie
|
|
67
|
-
COOKIE_HEADER="user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION"
|
|
68
|
-
|
|
69
|
-
# Test with curl
|
|
70
|
-
echo -n "Testing with filtered session: "
|
|
71
|
-
AUTH_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
72
|
-
-H "Cookie: $COOKIE_HEADER" \
|
|
73
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
74
|
-
"https://github.com/settings/profile")
|
|
75
|
-
|
|
76
|
-
if [ "$AUTH_CODE" = "200" ]; then
|
|
77
|
-
echo "✅ Authenticated (HTTP 200)"
|
|
78
|
-
else
|
|
79
|
-
echo "❌ Not authenticated (HTTP $AUTH_CODE)"
|
|
80
|
-
fi
|
|
81
|
-
else
|
|
82
|
-
echo "❌ No valid session cookie found"
|
|
83
|
-
fi
|
|
84
|
-
echo ""
|
|
85
|
-
|
|
86
|
-
# ============================================================================
|
|
87
|
-
# Method 3: Expired Cookie Filtering Comparison
|
|
88
|
-
# ============================================================================
|
|
89
|
-
echo "3️⃣ Method 3: Expired Cookie Filtering"
|
|
90
|
-
echo "─────────────────────────────────────"
|
|
91
|
-
|
|
92
|
-
DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
|
|
93
|
-
EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
|
|
94
|
-
|
|
95
|
-
echo "Cookies comparison:"
|
|
96
|
-
echo " • Without --include-expired: $DEFAULT_COUNT cookies"
|
|
97
|
-
echo " • With --include-expired: $EXPIRED_COUNT cookies"
|
|
98
|
-
|
|
99
|
-
if [ "$EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
|
|
100
|
-
DIFF=$((EXPIRED_COUNT - DEFAULT_COUNT))
|
|
101
|
-
echo " • ✅ Filtered out $DIFF expired cookies"
|
|
102
|
-
else
|
|
103
|
-
echo " • ℹ️ No expired cookies to filter (all cookies are valid)"
|
|
104
|
-
fi
|
|
105
|
-
echo ""
|
|
106
|
-
|
|
107
|
-
# ============================================================================
|
|
108
|
-
# Method 4: Systematic Endpoint Testing
|
|
109
|
-
# ============================================================================
|
|
110
|
-
echo "4️⃣ Method 4: Testing GitHub Endpoints"
|
|
111
|
-
echo "────────────────────────────────────"
|
|
112
|
-
|
|
113
|
-
# Function to test GitHub endpoints
|
|
114
|
-
test_endpoint() {
|
|
115
|
-
local name=$1
|
|
116
|
-
local url=$2
|
|
117
|
-
local check_string=$3
|
|
118
|
-
|
|
119
|
-
echo -n " • $name: "
|
|
120
|
-
|
|
121
|
-
COOKIES=$(get-cookie --url "$url" --render 2>/dev/null)
|
|
122
|
-
if [ -z "$COOKIES" ]; then
|
|
123
|
-
echo "No cookies found"
|
|
124
|
-
return 1
|
|
125
|
-
fi
|
|
126
|
-
|
|
127
|
-
RESPONSE=$(curl -s -L \
|
|
128
|
-
-H "Cookie: $COOKIES" \
|
|
129
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
|
|
130
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
131
|
-
"$url")
|
|
132
|
-
|
|
133
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
134
|
-
-H "Cookie: $COOKIES" \
|
|
135
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
136
|
-
"$url")
|
|
137
|
-
|
|
138
|
-
if echo "$RESPONSE" | grep -q "$check_string" > /dev/null 2>&1; then
|
|
139
|
-
echo "✅ Authenticated (HTTP $HTTP_CODE)"
|
|
140
|
-
return 0
|
|
141
|
-
elif [ "$HTTP_CODE" = "200" ]; then
|
|
142
|
-
echo "⚠️ Accessible but not authenticated (HTTP 200)"
|
|
143
|
-
return 1
|
|
144
|
-
elif [ "$HTTP_CODE" = "404" ]; then
|
|
145
|
-
echo "❌ Not found (HTTP 404)"
|
|
146
|
-
return 1
|
|
147
|
-
elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
|
|
148
|
-
echo "🔄 Redirected - not authenticated (HTTP $HTTP_CODE)"
|
|
149
|
-
return 1
|
|
150
|
-
else
|
|
151
|
-
echo "❌ Failed (HTTP $HTTP_CODE)"
|
|
152
|
-
return 1
|
|
153
|
-
fi
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
echo "Testing various GitHub endpoints:"
|
|
157
|
-
test_endpoint "Public profile" \
|
|
158
|
-
"https://github.com/$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)" \
|
|
159
|
-
"Follow"
|
|
160
|
-
|
|
161
|
-
test_endpoint "Settings page" \
|
|
162
|
-
"https://github.com/settings/profile" \
|
|
163
|
-
"Public profile"
|
|
164
|
-
|
|
165
|
-
test_endpoint "Notifications" \
|
|
166
|
-
"https://github.com/notifications" \
|
|
167
|
-
"notifications"
|
|
168
|
-
|
|
169
|
-
test_endpoint "Security settings" \
|
|
170
|
-
"https://github.com/settings/security" \
|
|
171
|
-
"Two-factor"
|
|
172
|
-
|
|
173
|
-
test_endpoint "SSH keys" \
|
|
174
|
-
"https://github.com/settings/keys" \
|
|
175
|
-
"SSH keys"
|
|
176
|
-
echo ""
|
|
177
|
-
|
|
178
|
-
# ============================================================================
|
|
179
|
-
# Method 5: Private Repository Access
|
|
180
|
-
# ============================================================================
|
|
181
|
-
echo "5️⃣ Method 5: Private Repository Access"
|
|
182
|
-
echo "───────────────────────────────────────"
|
|
183
|
-
|
|
184
|
-
# Get username
|
|
185
|
-
USERNAME=$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)
|
|
186
|
-
|
|
187
|
-
if [ -n "$USERNAME" ] && [ "$USERNAME" != "null" ]; then
|
|
188
|
-
echo "👤 Logged in as: $USERNAME"
|
|
189
|
-
echo ""
|
|
190
|
-
|
|
191
|
-
# Get valid session
|
|
192
|
-
FULL_SESSION=$(get-cookie user_session github.com --output json 2>/dev/null | \
|
|
193
|
-
jq -r '.[] | select(.value | length > 10) | .value' | head -1)
|
|
194
|
-
|
|
195
|
-
if [ -n "$FULL_SESSION" ]; then
|
|
196
|
-
COOKIE_HEADER="user_session=$FULL_SESSION; __Host-user_session_same_site=$FULL_SESSION"
|
|
197
|
-
|
|
198
|
-
echo "📊 Repository Statistics:"
|
|
199
|
-
REPOS_HTML=$(curl -s -L \
|
|
200
|
-
-H "Cookie: $COOKIE_HEADER" \
|
|
201
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
202
|
-
"https://github.com/$USERNAME?tab=repositories")
|
|
203
|
-
|
|
204
|
-
PUBLIC_COUNT=$(echo "$REPOS_HTML" | grep -o '>Public<' | wc -l | xargs)
|
|
205
|
-
PRIVATE_COUNT=$(echo "$REPOS_HTML" | grep -o '>Private<' | wc -l | xargs)
|
|
206
|
-
|
|
207
|
-
echo " • Public repositories: $PUBLIC_COUNT"
|
|
208
|
-
echo " • Private repositories: $PRIVATE_COUNT"
|
|
209
|
-
echo " • Total: $((PUBLIC_COUNT + PRIVATE_COUNT))"
|
|
210
|
-
|
|
211
|
-
if [ "$PRIVATE_COUNT" -gt 0 ]; then
|
|
212
|
-
echo ""
|
|
213
|
-
echo "✅ Can see private repositories!"
|
|
214
|
-
fi
|
|
215
|
-
else
|
|
216
|
-
echo "⚠️ Could not get valid session cookie"
|
|
217
|
-
fi
|
|
218
|
-
else
|
|
219
|
-
echo "❌ Could not detect username from cookies"
|
|
220
|
-
fi
|
|
221
|
-
echo ""
|
|
222
|
-
|
|
223
|
-
# ============================================================================
|
|
224
|
-
# Important: Web vs API Authentication
|
|
225
|
-
# ============================================================================
|
|
226
|
-
echo "⚠️ Important: Web vs API Authentication"
|
|
227
|
-
echo "─────────────────────────────────────────"
|
|
228
|
-
echo ""
|
|
229
|
-
echo "Browser cookies work for GitHub WEB pages, NOT the REST API:"
|
|
230
|
-
echo ""
|
|
231
|
-
echo "✅ Works with browser cookies:"
|
|
232
|
-
echo " • Viewing private repositories in browser"
|
|
233
|
-
echo " • Accessing settings pages"
|
|
234
|
-
echo " • Web scraping authenticated content"
|
|
235
|
-
echo ""
|
|
236
|
-
echo "❌ Does NOT work with browser cookies:"
|
|
237
|
-
echo " • GitHub REST API (api.github.com)"
|
|
238
|
-
echo " • GitHub GraphQL API"
|
|
239
|
-
echo " • Git operations (clone, push, pull)"
|
|
240
|
-
echo ""
|
|
241
|
-
echo "For API access, use:"
|
|
242
|
-
echo " • GitHub CLI: gh auth login"
|
|
243
|
-
echo " • Personal Access Tokens"
|
|
244
|
-
echo " • OAuth apps"
|
|
245
|
-
echo ""
|
|
246
|
-
|
|
247
|
-
# ============================================================================
|
|
248
|
-
# Practical Examples
|
|
249
|
-
# ============================================================================
|
|
250
|
-
echo "💡 Practical Examples"
|
|
251
|
-
echo "────────────────────"
|
|
252
|
-
echo ""
|
|
253
|
-
echo "# The Ultimate One-Liner:"
|
|
254
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://github.com/settings/profile --render)" \'
|
|
255
|
-
echo ' https://github.com/settings/profile'
|
|
256
|
-
echo ""
|
|
257
|
-
echo "# Download a file from a private repo:"
|
|
258
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://github.com/user/repo --render)" \'
|
|
259
|
-
echo ' https://github.com/user/repo/raw/main/file.txt'
|
|
260
|
-
echo ""
|
|
261
|
-
echo "# Access private gist:"
|
|
262
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://gist.github.com --render)" \'
|
|
263
|
-
echo ' https://gist.github.com/user/gist-id'
|
|
264
|
-
echo ""
|
|
265
|
-
|
|
266
|
-
# ============================================================================
|
|
267
|
-
# Debugging Tips
|
|
268
|
-
# ============================================================================
|
|
269
|
-
echo "🔍 Debugging Tips"
|
|
270
|
-
echo "────────────────"
|
|
271
|
-
echo ""
|
|
272
|
-
echo "If authentication isn't working:"
|
|
273
|
-
echo ""
|
|
274
|
-
echo "1. Check cookie quality:"
|
|
275
|
-
echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | {name, value: .value[:20], len: (.value | length)}'"'"
|
|
276
|
-
echo ""
|
|
277
|
-
echo "2. Check for expired cookies:"
|
|
278
|
-
echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | select(.expiry < now | todate)'"'"
|
|
279
|
-
echo ""
|
|
280
|
-
echo "3. Filter for valid session cookies:"
|
|
281
|
-
echo ' get-cookie --url <URL> --output json | jq -r '"'"'.[] | select(.name == "user_session" and (.value | length) > 20) | .value'"'"
|
|
282
|
-
echo ""
|
|
283
|
-
echo "4. Try specific browser profiles:"
|
|
284
|
-
echo ' get-cookie --url <URL> --browser chrome --render'
|
|
285
|
-
echo ""
|
|
286
|
-
|
|
287
|
-
echo "✅ GitHub authentication guide complete!"
|
|
288
|
-
echo ""
|
|
289
|
-
echo "💡 Key Insights:"
|
|
290
|
-
echo " • Default behavior filters expired cookies for better success"
|
|
291
|
-
echo " • Use --include-expired to include all cookies (debugging)"
|
|
292
|
-
echo " • For best results: get-cookie --url <URL> --render"
|
|
293
|
-
echo " • Some browsers may store invalid cookies that need filtering"
|
|
294
|
-
echo " • Browser cookies work for web pages, not the API"
|
|
295
|
-
|
package/examples/quick-start.sh
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Quick Start Guide: Essential get-cookie Patterns
|
|
4
|
-
# ================================================
|
|
5
|
-
# This script demonstrates the most common and practical patterns
|
|
6
|
-
# for using get-cookie in your daily workflow.
|
|
7
|
-
|
|
8
|
-
echo "🚀 get-cookie Quick Start Guide"
|
|
9
|
-
echo "==============================="
|
|
10
|
-
echo ""
|
|
11
|
-
|
|
12
|
-
# Example 1: Basic cookie extraction
|
|
13
|
-
echo "1️⃣ Basic Cookie Extraction"
|
|
14
|
-
echo "──────────────────────────"
|
|
15
|
-
echo ""
|
|
16
|
-
echo "Get a single cookie value:"
|
|
17
|
-
echo ' get-cookie user_session github.com --render'
|
|
18
|
-
echo ""
|
|
19
|
-
USER_SESSION=$(get-cookie user_session github.com --render 2>/dev/null | head -1)
|
|
20
|
-
if [ -n "$USER_SESSION" ]; then
|
|
21
|
-
echo " ✅ Found: ${USER_SESSION:0:30}..."
|
|
22
|
-
else
|
|
23
|
-
echo " ℹ️ No user_session cookie found (example only)"
|
|
24
|
-
fi
|
|
25
|
-
echo ""
|
|
26
|
-
|
|
27
|
-
# Example 2: Get all cookies for a domain
|
|
28
|
-
echo "2️⃣ Get All Cookies for a Domain"
|
|
29
|
-
echo "───────────────────────────────"
|
|
30
|
-
echo ""
|
|
31
|
-
echo "Get all cookies (use % as wildcard):"
|
|
32
|
-
echo ' get-cookie % github.com --output json | jq length'
|
|
33
|
-
echo ""
|
|
34
|
-
COOKIE_COUNT=$(get-cookie % github.com --output json 2>/dev/null | jq 'length // 0')
|
|
35
|
-
echo " Found $COOKIE_COUNT cookies for github.com"
|
|
36
|
-
echo ""
|
|
37
|
-
|
|
38
|
-
# Example 3: The Perfect One-Liner for curl
|
|
39
|
-
echo "3️⃣ One-Liner for curl (Most Common Pattern)"
|
|
40
|
-
echo "───────────────────────────────────────────"
|
|
41
|
-
echo ""
|
|
42
|
-
echo "The --url flag automatically gets all cookies for a URL:"
|
|
43
|
-
echo ' curl -H "Cookie: $(get-cookie --url <URL> --render)" <URL>'
|
|
44
|
-
echo ""
|
|
45
|
-
echo "Example:"
|
|
46
|
-
echo ' curl -H "Cookie: $(get-cookie --url https://github.com/settings/profile --render)" \'
|
|
47
|
-
echo ' https://github.com/settings/profile'
|
|
48
|
-
echo ""
|
|
49
|
-
|
|
50
|
-
# Example 4: Reusable Shell Function
|
|
51
|
-
echo "4️⃣ Reusable Shell Function (Add to .bashrc/.zshrc)"
|
|
52
|
-
echo "──────────────────────────────────────────────────"
|
|
53
|
-
echo ""
|
|
54
|
-
cat << 'EOF'
|
|
55
|
-
# Add this function to your shell config for easy authenticated requests
|
|
56
|
-
auth_curl() {
|
|
57
|
-
local url=$1
|
|
58
|
-
shift
|
|
59
|
-
curl -H "Cookie: $(get-cookie --url "$url" --render 2>/dev/null)" "$@" "$url"
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
# Usage examples:
|
|
63
|
-
# auth_curl https://github.com/settings/profile -s | grep username
|
|
64
|
-
# auth_curl https://example.com/api/data -o data.json
|
|
65
|
-
EOF
|
|
66
|
-
echo ""
|
|
67
|
-
|
|
68
|
-
# Example 5: Quick Login Check
|
|
69
|
-
echo "5️⃣ Quick Login Status Check"
|
|
70
|
-
echo "───────────────────────────"
|
|
71
|
-
echo ""
|
|
72
|
-
echo "Check if you're logged into a site:"
|
|
73
|
-
echo ' get-cookie user_session github.com --render && echo "✅ Logged in" || echo "❌ Not logged in"'
|
|
74
|
-
echo ""
|
|
75
|
-
if get-cookie user_session github.com --render 2>/dev/null | grep -q "user_session="; then
|
|
76
|
-
echo " ✅ You appear to be logged into GitHub"
|
|
77
|
-
else
|
|
78
|
-
echo " ❌ Not logged into GitHub (or no cookies found)"
|
|
79
|
-
fi
|
|
80
|
-
echo ""
|
|
81
|
-
|
|
82
|
-
# Example 6: Save Cookies to File
|
|
83
|
-
echo "6️⃣ Save Cookies for Later Use"
|
|
84
|
-
echo "──────────────────────────────"
|
|
85
|
-
echo ""
|
|
86
|
-
echo "Backup all cookies to JSON:"
|
|
87
|
-
echo ' get-cookie % github.com --output json > github-cookies-backup.json'
|
|
88
|
-
echo ""
|
|
89
|
-
echo "Restore and use with curl:"
|
|
90
|
-
echo ' COOKIES=$(jq -r ".[] | \"\(.name)=\(.value)\"" github-cookies-backup.json | tr "\n" ";")'
|
|
91
|
-
echo ' curl -H "Cookie: $COOKIES" https://github.com'
|
|
92
|
-
echo ""
|
|
93
|
-
|
|
94
|
-
# Example 7: Common Output Formats
|
|
95
|
-
echo "7️⃣ Output Format Options"
|
|
96
|
-
echo "────────────────────────"
|
|
97
|
-
echo ""
|
|
98
|
-
echo "JSON (for scripting):"
|
|
99
|
-
echo ' get-cookie user_session github.com --output json'
|
|
100
|
-
echo ""
|
|
101
|
-
echo "Rendered (for curl headers):"
|
|
102
|
-
echo ' get-cookie user_session github.com --render'
|
|
103
|
-
echo ""
|
|
104
|
-
echo "Dump (human-readable debug):"
|
|
105
|
-
echo ' get-cookie user_session github.com --dump'
|
|
106
|
-
echo ""
|
|
107
|
-
|
|
108
|
-
echo "📚 Next Steps"
|
|
109
|
-
echo "───────────"
|
|
110
|
-
echo "• See curl-integration.sh for comprehensive curl patterns"
|
|
111
|
-
echo "• See github-auth.sh for GitHub-specific authentication"
|
|
112
|
-
echo "• See features-demo.sh for advanced CLI features"
|
|
113
|
-
echo ""
|
|
114
|
-
echo "✅ Quick start complete!"
|
|
115
|
-
|