@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.
- package/.claude/settings.local.json +3 -0
- package/.dependency-cruiser.js +277 -0
- package/.husky/commit-msg +0 -0
- package/.husky/pre-commit +0 -0
- package/.husky/pre-push +0 -0
- package/README.md +106 -48
- package/biome.json +39 -16
- package/dist/cli.cjs +76 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +76 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +647 -126
- package/dist/index.d.ts +647 -126
- package/dist/index.js +76 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +23 -2
- package/examples/auth-tokens.ts +143 -0
- package/examples/chrome-cookies-demo.sh +117 -0
- package/examples/chrome-profile-demo.sh +126 -0
- package/examples/cli-examples.sh +0 -0
- package/examples/comprehensive-demo.ts +202 -0
- package/examples/curl-demo.sh +102 -0
- package/examples/curl-integration.sh +276 -0
- package/examples/curl-with-url.sh +136 -0
- package/examples/deduplication-demo.sh +110 -0
- package/examples/final-chrome-demo.sh +115 -0
- package/examples/github-api.sh +101 -0
- package/examples/github-private-access.sh +118 -0
- package/examples/list-profiles-demo.sh +120 -0
- package/examples/proper-curl-usage.sh +120 -0
- package/examples/simple-curl.sh +95 -0
- package/examples/test-expired-filtering.sh +68 -0
- package/examples/test-github-access.sh +245 -0
- package/examples/test-github-auth-improved.sh +136 -0
- package/examples/working-curl.sh +117 -0
- package/examples/working-github-auth.sh +87 -0
- package/package.json +46 -27
- package/tsconfig.cli.json +5 -1
- package/tsup.cli.ts +31 -1
- package/tsup.lib.ts +11 -1
|
@@ -0,0 +1,102 @@
|
|
|
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!"
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# ============================================================================
|
|
4
|
+
# get-cookie + curl Integration Examples
|
|
5
|
+
#
|
|
6
|
+
# This script demonstrates how to extract browser cookies and use them
|
|
7
|
+
# with curl for authenticated API requests. This is useful for:
|
|
8
|
+
# - Testing APIs with real authentication
|
|
9
|
+
# - Automating tasks that require browser sessions
|
|
10
|
+
# - Debugging authentication issues
|
|
11
|
+
# ============================================================================
|
|
12
|
+
|
|
13
|
+
# Colors for output
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
GREEN='\033[0;32m'
|
|
16
|
+
YELLOW='\033[1;33m'
|
|
17
|
+
BLUE='\033[0;34m'
|
|
18
|
+
NC='\033[0m' # No Color
|
|
19
|
+
|
|
20
|
+
# Use the globally installed get-cookie binary
|
|
21
|
+
GET_COOKIE="get-cookie"
|
|
22
|
+
|
|
23
|
+
echo -e "${BLUE}🍪 get-cookie + curl Integration Examples${NC}"
|
|
24
|
+
echo "================================================"
|
|
25
|
+
|
|
26
|
+
# ============================================================================
|
|
27
|
+
# Example 1: GitHub API with session cookie
|
|
28
|
+
# ============================================================================
|
|
29
|
+
echo -e "\n${YELLOW}Example 1: GitHub API Authentication${NC}"
|
|
30
|
+
echo "----------------------------------------"
|
|
31
|
+
|
|
32
|
+
# Extract GitHub session cookie
|
|
33
|
+
echo -e "${GREEN}Extracting GitHub session cookie...${NC}"
|
|
34
|
+
GITHUB_SESSION=$($GET_COOKIE user_session github.com 2>/dev/null | head -1)
|
|
35
|
+
|
|
36
|
+
if [ -n "$GITHUB_SESSION" ]; then
|
|
37
|
+
echo "✓ Found GitHub session cookie"
|
|
38
|
+
|
|
39
|
+
# Get current user info from GitHub API
|
|
40
|
+
echo -e "\n${GREEN}Fetching user info from GitHub API...${NC}"
|
|
41
|
+
RESPONSE=$(curl -s -H "Cookie: user_session=$GITHUB_SESSION" \
|
|
42
|
+
-H "User-Agent: get-cookie-demo" \
|
|
43
|
+
https://api.github.com/user)
|
|
44
|
+
|
|
45
|
+
# Check if we got a valid response
|
|
46
|
+
if echo "$RESPONSE" | grep -q '"login"'; then
|
|
47
|
+
USERNAME=$(echo "$RESPONSE" | grep -o '"login":"[^"]*' | cut -d'"' -f4)
|
|
48
|
+
NAME=$(echo "$RESPONSE" | grep -o '"name":"[^"]*' | cut -d'"' -f4)
|
|
49
|
+
echo -e "${GREEN}✓ Successfully authenticated as: $NAME (@$USERNAME)${NC}"
|
|
50
|
+
else
|
|
51
|
+
echo -e "${RED}✗ Authentication failed - cookie might be expired${NC}"
|
|
52
|
+
fi
|
|
53
|
+
else
|
|
54
|
+
echo -e "${RED}✗ No GitHub session cookie found${NC}"
|
|
55
|
+
echo " Make sure you're logged into GitHub in Chrome/Firefox"
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# ============================================================================
|
|
59
|
+
# Example 2: Multiple cookies for complex authentication
|
|
60
|
+
# ============================================================================
|
|
61
|
+
echo -e "\n${YELLOW}Example 2: Multiple Cookie Authentication${NC}"
|
|
62
|
+
echo "----------------------------------------"
|
|
63
|
+
|
|
64
|
+
# Some sites require multiple cookies for authentication
|
|
65
|
+
# Extract all GitHub cookies and format for curl
|
|
66
|
+
echo -e "${GREEN}Extracting all GitHub cookies...${NC}"
|
|
67
|
+
|
|
68
|
+
# Get cookies in JSON format
|
|
69
|
+
COOKIES_JSON=$($GET_COOKIE % github.com --output json 2>/dev/null)
|
|
70
|
+
|
|
71
|
+
if [ -n "$COOKIES_JSON" ]; then
|
|
72
|
+
# Count cookies
|
|
73
|
+
COOKIE_COUNT=$(echo "$COOKIES_JSON" | jq 'length')
|
|
74
|
+
echo "✓ Found $COOKIE_COUNT GitHub cookies"
|
|
75
|
+
|
|
76
|
+
# Build cookie header with multiple cookies
|
|
77
|
+
COOKIE_HEADER=$(echo "$COOKIES_JSON" | jq -r '.[] | "\(.name)=\(.value)"' | head -5 | paste -sd '; ')
|
|
78
|
+
|
|
79
|
+
if [ -n "$COOKIE_HEADER" ]; then
|
|
80
|
+
echo -e "\n${GREEN}Testing with multiple cookies...${NC}"
|
|
81
|
+
# Make request with multiple cookies
|
|
82
|
+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
83
|
+
-H "Cookie: $COOKIE_HEADER" \
|
|
84
|
+
-H "User-Agent: get-cookie-demo" \
|
|
85
|
+
https://github.com/settings/profile)
|
|
86
|
+
|
|
87
|
+
if [ "$STATUS" = "200" ]; then
|
|
88
|
+
echo -e "${GREEN}✓ Successfully accessed protected page (HTTP $STATUS)${NC}"
|
|
89
|
+
else
|
|
90
|
+
echo -e "${RED}✗ Access denied (HTTP $STATUS)${NC}"
|
|
91
|
+
fi
|
|
92
|
+
fi
|
|
93
|
+
else
|
|
94
|
+
echo -e "${RED}✗ Failed to extract cookies${NC}"
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
# ============================================================================
|
|
98
|
+
# Example 3: Download protected content
|
|
99
|
+
# ============================================================================
|
|
100
|
+
echo -e "\n${YELLOW}Example 3: Download Protected Content${NC}"
|
|
101
|
+
echo "----------------------------------------"
|
|
102
|
+
|
|
103
|
+
# Example: Download a file that requires authentication
|
|
104
|
+
echo -e "${GREEN}Preparing authenticated download...${NC}"
|
|
105
|
+
|
|
106
|
+
# Get session cookie for a specific domain
|
|
107
|
+
DOMAIN="github.com"
|
|
108
|
+
SESSION=$($GET_COOKIE user_session $DOMAIN 2>/dev/null | head -1)
|
|
109
|
+
|
|
110
|
+
if [ -n "$SESSION" ]; then
|
|
111
|
+
echo "✓ Authentication cookie ready"
|
|
112
|
+
|
|
113
|
+
# Example: Download user's avatar (requires authentication for private profiles)
|
|
114
|
+
echo -e "\n${GREEN}Example curl command for authenticated download:${NC}"
|
|
115
|
+
echo -e "${BLUE}curl -H \"Cookie: user_session=\$SESSION\" \\
|
|
116
|
+
-H \"User-Agent: YourApp\" \\
|
|
117
|
+
-o avatar.jpg \\
|
|
118
|
+
https://github.com/username.png${NC}"
|
|
119
|
+
else
|
|
120
|
+
echo -e "${RED}✗ No session cookie available${NC}"
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
# ============================================================================
|
|
124
|
+
# Example 4: Function for easy cookie extraction
|
|
125
|
+
# ============================================================================
|
|
126
|
+
echo -e "\n${YELLOW}Example 4: Reusable Shell Function${NC}"
|
|
127
|
+
echo "----------------------------------------"
|
|
128
|
+
|
|
129
|
+
# Define a reusable function
|
|
130
|
+
get_cookie_for_curl() {
|
|
131
|
+
local cookie_name=$1
|
|
132
|
+
local domain=$2
|
|
133
|
+
local cookie_value=$($GET_COOKIE "$cookie_name" "$domain" 2>/dev/null | head -1)
|
|
134
|
+
|
|
135
|
+
if [ -n "$cookie_value" ]; then
|
|
136
|
+
echo "$cookie_name=$cookie_value"
|
|
137
|
+
return 0
|
|
138
|
+
else
|
|
139
|
+
echo ""
|
|
140
|
+
return 1
|
|
141
|
+
fi
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# Demonstrate the function
|
|
145
|
+
echo -e "${GREEN}Using reusable function to build cookie header...${NC}"
|
|
146
|
+
|
|
147
|
+
# Build a cookie header with multiple specific cookies
|
|
148
|
+
COOKIE_HEADER=""
|
|
149
|
+
for cookie in "user_session" "dotcom_user" "_gh_sess"; do
|
|
150
|
+
if cookie_value=$(get_cookie_for_curl "$cookie" "github.com"); then
|
|
151
|
+
if [ -n "$COOKIE_HEADER" ]; then
|
|
152
|
+
COOKIE_HEADER="$COOKIE_HEADER; $cookie_value"
|
|
153
|
+
else
|
|
154
|
+
COOKIE_HEADER="$cookie_value"
|
|
155
|
+
fi
|
|
156
|
+
echo " ✓ Added $cookie"
|
|
157
|
+
else
|
|
158
|
+
echo " ✗ Skipped $cookie (not found)"
|
|
159
|
+
fi
|
|
160
|
+
done
|
|
161
|
+
|
|
162
|
+
if [ -n "$COOKIE_HEADER" ]; then
|
|
163
|
+
echo -e "\n${GREEN}Complete Cookie header for curl:${NC}"
|
|
164
|
+
echo -e "${BLUE}Cookie: $COOKIE_HEADER${NC}"
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
# ============================================================================
|
|
168
|
+
# Example 5: POST request with cookies
|
|
169
|
+
# ============================================================================
|
|
170
|
+
echo -e "\n${YELLOW}Example 5: POST Request with Authentication${NC}"
|
|
171
|
+
echo "----------------------------------------"
|
|
172
|
+
|
|
173
|
+
echo -e "${GREEN}Example: Creating a GitHub gist with authentication${NC}"
|
|
174
|
+
|
|
175
|
+
# Get GitHub session
|
|
176
|
+
SESSION=$($GET_COOKIE user_session github.com 2>/dev/null | head -1)
|
|
177
|
+
CSRF=$($GET_COOKIE _gh_sess github.com 2>/dev/null | head -1)
|
|
178
|
+
|
|
179
|
+
if [ -n "$SESSION" ]; then
|
|
180
|
+
echo -e "\n${BLUE}Example POST command:${NC}"
|
|
181
|
+
cat << 'EOF'
|
|
182
|
+
curl -X POST \
|
|
183
|
+
-H "Cookie: user_session=$SESSION; _gh_sess=$CSRF" \
|
|
184
|
+
-H "Content-Type: application/json" \
|
|
185
|
+
-H "User-Agent: get-cookie-demo" \
|
|
186
|
+
-d '{
|
|
187
|
+
"description": "Created via API",
|
|
188
|
+
"public": false,
|
|
189
|
+
"files": {
|
|
190
|
+
"test.txt": {
|
|
191
|
+
"content": "Hello from get-cookie + curl!"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}' \
|
|
195
|
+
https://api.github.com/gists
|
|
196
|
+
EOF
|
|
197
|
+
else
|
|
198
|
+
echo -e "${RED}✗ Authentication cookies not available${NC}"
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
# ============================================================================
|
|
202
|
+
# Example 6: Cookie validation
|
|
203
|
+
# ============================================================================
|
|
204
|
+
echo -e "\n${YELLOW}Example 6: Cookie Validation${NC}"
|
|
205
|
+
echo "----------------------------------------"
|
|
206
|
+
|
|
207
|
+
validate_cookie() {
|
|
208
|
+
local domain=$1
|
|
209
|
+
local cookie_name=$2
|
|
210
|
+
|
|
211
|
+
echo -e "${GREEN}Validating $cookie_name for $domain...${NC}"
|
|
212
|
+
|
|
213
|
+
# Get cookie with metadata
|
|
214
|
+
COOKIE_JSON=$($GET_COOKIE "$cookie_name" "$domain" --output json 2>/dev/null)
|
|
215
|
+
|
|
216
|
+
if [ -n "$COOKIE_JSON" ] && [ "$COOKIE_JSON" != "[]" ]; then
|
|
217
|
+
# Parse cookie details
|
|
218
|
+
EXPIRY=$(echo "$COOKIE_JSON" | jq -r '.[0].expiry' 2>/dev/null)
|
|
219
|
+
BROWSER=$(echo "$COOKIE_JSON" | jq -r '.[0].meta.browser' 2>/dev/null)
|
|
220
|
+
DECRYPTED=$(echo "$COOKIE_JSON" | jq -r '.[0].meta.decrypted' 2>/dev/null)
|
|
221
|
+
|
|
222
|
+
echo " ✓ Cookie found"
|
|
223
|
+
echo " Browser: $BROWSER"
|
|
224
|
+
echo " Decrypted: $DECRYPTED"
|
|
225
|
+
|
|
226
|
+
# Check if expired
|
|
227
|
+
if [ "$EXPIRY" != "null" ] && [ "$EXPIRY" != "Infinity" ]; then
|
|
228
|
+
EXPIRY_TIMESTAMP=$(date -d "$EXPIRY" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "${EXPIRY%%.*}" +%s 2>/dev/null)
|
|
229
|
+
CURRENT_TIMESTAMP=$(date +%s)
|
|
230
|
+
|
|
231
|
+
if [ -n "$EXPIRY_TIMESTAMP" ]; then
|
|
232
|
+
if [ "$EXPIRY_TIMESTAMP" -gt "$CURRENT_TIMESTAMP" ]; then
|
|
233
|
+
DAYS_LEFT=$(( ($EXPIRY_TIMESTAMP - $CURRENT_TIMESTAMP) / 86400 ))
|
|
234
|
+
echo " Valid for: $DAYS_LEFT days"
|
|
235
|
+
else
|
|
236
|
+
echo -e " ${RED}⚠ EXPIRED${NC}"
|
|
237
|
+
fi
|
|
238
|
+
else
|
|
239
|
+
echo " Expiry: $EXPIRY"
|
|
240
|
+
fi
|
|
241
|
+
else
|
|
242
|
+
echo " Type: Session cookie"
|
|
243
|
+
fi
|
|
244
|
+
return 0
|
|
245
|
+
else
|
|
246
|
+
echo -e " ${RED}✗ Cookie not found${NC}"
|
|
247
|
+
return 1
|
|
248
|
+
fi
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
# Validate some common cookies
|
|
252
|
+
validate_cookie "github.com" "user_session"
|
|
253
|
+
|
|
254
|
+
# ============================================================================
|
|
255
|
+
# Tips and Best Practices
|
|
256
|
+
# ============================================================================
|
|
257
|
+
echo -e "\n${BLUE}📚 Tips and Best Practices${NC}"
|
|
258
|
+
echo "================================================"
|
|
259
|
+
echo "
|
|
260
|
+
1. ${YELLOW}Security:${NC} Never log or save cookie values in scripts
|
|
261
|
+
2. ${YELLOW}Expiration:${NC} Check cookie expiry before using them
|
|
262
|
+
3. ${YELLOW}User-Agent:${NC} Always set a User-Agent header with curl
|
|
263
|
+
4. ${YELLOW}CSRF Tokens:${NC} Some APIs require CSRF tokens in addition to session cookies
|
|
264
|
+
5. ${YELLOW}Rate Limiting:${NC} Respect API rate limits when using automation
|
|
265
|
+
|
|
266
|
+
${GREEN}Example one-liner to test authentication:${NC}
|
|
267
|
+
${BLUE}get-cookie user_session github.com | xargs -I {} curl -s -H \"Cookie: user_session={}\" https://api.github.com/user | jq .login${NC}
|
|
268
|
+
|
|
269
|
+
${GREEN}Example to save cookies to a file:${NC}
|
|
270
|
+
${BLUE}get-cookie % domain.com --output json > cookies.json${NC}
|
|
271
|
+
|
|
272
|
+
${GREEN}Example to use with wget instead of curl:${NC}
|
|
273
|
+
${BLUE}wget --header=\"Cookie: \$(get-cookie session domain.com)\" https://domain.com/protected${NC}
|
|
274
|
+
"
|
|
275
|
+
|
|
276
|
+
echo -e "${GREEN}✅ Examples completed!${NC}"
|
|
@@ -0,0 +1,136 @@
|
|
|
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!"
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Demonstration of the new cookie deduplication feature
|
|
4
|
+
echo "🍪 Cookie Deduplication Feature Demo"
|
|
5
|
+
echo "===================================="
|
|
6
|
+
echo ""
|
|
7
|
+
echo "This demo shows how get-cookie now handles duplicate cookies"
|
|
8
|
+
echo "from Chrome profiles by default, keeping the most valid one."
|
|
9
|
+
echo ""
|
|
10
|
+
|
|
11
|
+
# Show the problem
|
|
12
|
+
echo "1️⃣ The Problem: Chrome Duplicate Cookies"
|
|
13
|
+
echo "────────────────────────────────────────"
|
|
14
|
+
echo "Chrome can store duplicate cookies from different profiles."
|
|
15
|
+
echo "Let's see what happens with --include-all (old behavior):"
|
|
16
|
+
echo ""
|
|
17
|
+
|
|
18
|
+
echo "Command: get-cookie user_session github.com --browser chrome --output json --include-all"
|
|
19
|
+
echo ""
|
|
20
|
+
get-cookie user_session github.com --browser chrome --output json --include-all 2>/dev/null | \
|
|
21
|
+
jq -r '.[] | " • Value: \(.value[0:20])... (\(.value | length) chars)"'
|
|
22
|
+
echo ""
|
|
23
|
+
|
|
24
|
+
# Show the solution
|
|
25
|
+
echo "2️⃣ The Solution: Automatic Deduplication (Default)"
|
|
26
|
+
echo "──────────────────────────────────────────────────"
|
|
27
|
+
echo "By default, get-cookie now keeps only the most valid cookie:"
|
|
28
|
+
echo ""
|
|
29
|
+
|
|
30
|
+
echo "Command: get-cookie user_session github.com --browser chrome --output json"
|
|
31
|
+
echo ""
|
|
32
|
+
get-cookie user_session github.com --browser chrome --output json 2>/dev/null | \
|
|
33
|
+
jq -r '.[] | " • Value: \(.value[0:20])... (\(.value | length) chars)"'
|
|
34
|
+
echo ""
|
|
35
|
+
|
|
36
|
+
# Demonstrate the render difference
|
|
37
|
+
echo "3️⃣ Impact on --render Output"
|
|
38
|
+
echo "───────────────────────────"
|
|
39
|
+
echo ""
|
|
40
|
+
|
|
41
|
+
echo "With --include-all (all duplicates):"
|
|
42
|
+
RENDER_ALL=$(get-cookie user_session github.com --browser chrome --render --include-all 2>/dev/null)
|
|
43
|
+
echo " ${RENDER_ALL:0:60}..."
|
|
44
|
+
echo " Length: $(echo "$RENDER_ALL" | wc -c) chars"
|
|
45
|
+
echo ""
|
|
46
|
+
|
|
47
|
+
echo "Default (deduplicated):"
|
|
48
|
+
RENDER_DEDUP=$(get-cookie user_session github.com --browser chrome --render 2>/dev/null)
|
|
49
|
+
echo " $RENDER_DEDUP"
|
|
50
|
+
echo " Length: $(echo "$RENDER_DEDUP" | wc -c) chars"
|
|
51
|
+
echo ""
|
|
52
|
+
|
|
53
|
+
# Show how it works with curl
|
|
54
|
+
echo "4️⃣ Using with curl"
|
|
55
|
+
echo "────────────────"
|
|
56
|
+
echo "The deduplication ensures curl gets the valid cookie:"
|
|
57
|
+
echo ""
|
|
58
|
+
|
|
59
|
+
echo "Command: curl -H \"Cookie: \$(get-cookie --url <URL> --browser chrome --render)\" <URL>"
|
|
60
|
+
echo ""
|
|
61
|
+
echo "Example for GitHub:"
|
|
62
|
+
COOKIES=$(get-cookie --url https://github.com --browser chrome --render 2>/dev/null)
|
|
63
|
+
echo " Cookie count: $(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +)"
|
|
64
|
+
echo " user_session value length: $(echo "$COOKIES" | grep -o 'user_session=[^;]*' | cut -d'=' -f2 | wc -c) chars"
|
|
65
|
+
echo ""
|
|
66
|
+
|
|
67
|
+
# Show all duplicates
|
|
68
|
+
echo "5️⃣ Viewing All Duplicates"
|
|
69
|
+
echo "───────────────────────"
|
|
70
|
+
echo "To see all duplicate cookies (for debugging), use --include-all:"
|
|
71
|
+
echo ""
|
|
72
|
+
|
|
73
|
+
echo "Command: get-cookie % github.com --browser chrome --output json --include-all"
|
|
74
|
+
echo ""
|
|
75
|
+
echo "Duplicate cookie names found:"
|
|
76
|
+
get-cookie % github.com --browser chrome --output json --include-all 2>/dev/null | \
|
|
77
|
+
jq -r '[.[] | .name] | group_by(.) | map(select(length > 1)) | map(.[0]) | .[]' | \
|
|
78
|
+
sort | uniq | while read name; do
|
|
79
|
+
COUNT=$(get-cookie "$name" github.com --browser chrome --output json --include-all 2>/dev/null | jq 'length')
|
|
80
|
+
if [ "$COUNT" -gt 1 ]; then
|
|
81
|
+
echo " • $name: $COUNT copies"
|
|
82
|
+
fi
|
|
83
|
+
done
|
|
84
|
+
echo ""
|
|
85
|
+
|
|
86
|
+
# Summary
|
|
87
|
+
echo "📊 Summary"
|
|
88
|
+
echo "────────"
|
|
89
|
+
echo ""
|
|
90
|
+
|
|
91
|
+
# Count cookies with and without deduplication
|
|
92
|
+
TOTAL_ALL=$(get-cookie % github.com --browser chrome --output json --include-all 2>/dev/null | jq 'length')
|
|
93
|
+
TOTAL_DEDUP=$(get-cookie % github.com --browser chrome --output json 2>/dev/null | jq 'length')
|
|
94
|
+
REMOVED=$((TOTAL_ALL - TOTAL_DEDUP))
|
|
95
|
+
|
|
96
|
+
echo "Chrome cookies for github.com:"
|
|
97
|
+
echo " • With --include-all: $TOTAL_ALL cookies"
|
|
98
|
+
echo " • Default (deduplicated): $TOTAL_DEDUP cookies"
|
|
99
|
+
echo " • Duplicates removed: $REMOVED"
|
|
100
|
+
echo ""
|
|
101
|
+
|
|
102
|
+
echo "💡 Key Points:"
|
|
103
|
+
echo "────────────"
|
|
104
|
+
echo "• Deduplication is ON by default (keeps longest/newest cookie)"
|
|
105
|
+
echo "• Use --include-all to see all duplicates"
|
|
106
|
+
echo "• Combines with --include-expired for complete control"
|
|
107
|
+
echo "• Solves the Chrome \"truncated cookie\" problem"
|
|
108
|
+
echo ""
|
|
109
|
+
|
|
110
|
+
echo "✅ The deduplication feature ensures you get valid cookies for authentication!"
|