@mherod/get-cookie 4.4.0 ā 4.4.2
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/.husky/commit-msg +0 -1
- package/.husky/pre-commit +10 -1
- package/.husky/pre-push +15 -0
- package/dist/cli.cjs +10 -10
- 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 +31 -174
- package/dist/index.d.ts +31 -174
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/README.md +40 -6
- package/examples/cli-examples.sh +0 -0
- package/examples/curl-integration.sh +195 -160
- package/examples/features-demo.sh +260 -0
- package/examples/github-auth.sh +295 -0
- package/examples/quick-start.sh +115 -0
- package/package.json +62 -68
- package/tsup.cli.ts +1 -0
- package/tsup.lib.ts +9 -1
- package/examples/chrome-cookies-demo.sh +0 -117
- package/examples/chrome-profile-demo.sh +0 -126
- package/examples/curl-demo.sh +0 -102
- package/examples/curl-with-url.sh +0 -136
- package/examples/deduplication-demo.sh +0 -110
- package/examples/final-chrome-demo.sh +0 -115
- package/examples/github-api.sh +0 -101
- package/examples/github-private-access.sh +0 -118
- package/examples/list-profiles-demo.sh +0 -120
- package/examples/proper-curl-usage.sh +0 -120
- package/examples/simple-curl.sh +0 -95
- package/examples/test-expired-filtering.sh +0 -68
- package/examples/test-github-access.sh +0 -245
- package/examples/test-github-auth-improved.sh +0 -136
- package/examples/working-curl.sh +0 -117
- package/examples/working-github-auth.sh +0 -87
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Ultimate get-cookie + curl integration using --url flag
|
|
4
|
-
echo "š get-cookie + curl: The Perfect Integration"
|
|
5
|
-
echo "============================================="
|
|
6
|
-
echo ""
|
|
7
|
-
echo "The --url flag automatically gets all cookies for a specific URL!"
|
|
8
|
-
echo ""
|
|
9
|
-
|
|
10
|
-
# Example 1: Simple one-liner for any URL
|
|
11
|
-
echo "1ļøā£ One-liner to curl any URL with cookies:"
|
|
12
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
13
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://github.com/settings/profile --render)" https://github.com/settings/profile'
|
|
14
|
-
echo ""
|
|
15
|
-
|
|
16
|
-
# Example 2: Function for easy authenticated requests
|
|
17
|
-
authenticated_curl() {
|
|
18
|
-
local url=$1
|
|
19
|
-
shift # Remove first argument, pass the rest to curl
|
|
20
|
-
|
|
21
|
-
# Get cookies for this specific URL
|
|
22
|
-
local cookies=$(get-cookie --url "$url" --render 2>/dev/null)
|
|
23
|
-
|
|
24
|
-
if [ -n "$cookies" ]; then
|
|
25
|
-
curl -H "Cookie: $cookies" "$@" "$url"
|
|
26
|
-
else
|
|
27
|
-
echo "No cookies found for $url" >&2
|
|
28
|
-
curl "$@" "$url"
|
|
29
|
-
fi
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
echo "2ļøā£ Testing authenticated requests:"
|
|
33
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
34
|
-
|
|
35
|
-
# Test GitHub settings page
|
|
36
|
-
echo "⢠GitHub Settings:"
|
|
37
|
-
HTTP_CODE=$(authenticated_curl "https://github.com/settings/profile" -s -o /dev/null -w "%{http_code}")
|
|
38
|
-
if [ "$HTTP_CODE" = "200" ]; then
|
|
39
|
-
echo " ā
Successfully accessed (HTTP 200)"
|
|
40
|
-
elif [ "$HTTP_CODE" = "302" ]; then
|
|
41
|
-
echo " ā ļø Redirected to login (HTTP 302)"
|
|
42
|
-
else
|
|
43
|
-
echo " ā Failed (HTTP $HTTP_CODE)"
|
|
44
|
-
fi
|
|
45
|
-
|
|
46
|
-
# Test Stack Overflow profile
|
|
47
|
-
echo "⢠Stack Overflow Profile:"
|
|
48
|
-
HTTP_CODE=$(authenticated_curl "https://stackoverflow.com/users/edit/current" -s -o /dev/null -w "%{http_code}")
|
|
49
|
-
if [ "$HTTP_CODE" = "200" ]; then
|
|
50
|
-
echo " ā
Successfully accessed (HTTP 200)"
|
|
51
|
-
elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "404" ]; then
|
|
52
|
-
echo " ā ļø Not logged in or no profile (HTTP $HTTP_CODE)"
|
|
53
|
-
else
|
|
54
|
-
echo " ā Failed (HTTP $HTTP_CODE)"
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
echo ""
|
|
58
|
-
echo "3ļøā£ Practical Examples:"
|
|
59
|
-
echo "āāāāāāāāāāāāāāāāāāāā"
|
|
60
|
-
|
|
61
|
-
# Download a file with authentication
|
|
62
|
-
echo "⢠Download authenticated content:"
|
|
63
|
-
echo ' curl -H "Cookie: $(get-cookie --url https://example.com/private/file.pdf --render)" \\'
|
|
64
|
-
echo ' -o file.pdf https://example.com/private/file.pdf'
|
|
65
|
-
|
|
66
|
-
# POST request with cookies
|
|
67
|
-
echo ""
|
|
68
|
-
echo "⢠POST with authentication:"
|
|
69
|
-
echo ' curl -X POST \\'
|
|
70
|
-
echo ' -H "Cookie: $(get-cookie --url https://api.example.com/endpoint --render)" \\'
|
|
71
|
-
echo ' -H "Content-Type: application/json" \\'
|
|
72
|
-
echo ' -d '"'"'{"key": "value"}'"'"' \\'
|
|
73
|
-
echo ' https://api.example.com/endpoint'
|
|
74
|
-
|
|
75
|
-
# Follow redirects with cookies
|
|
76
|
-
echo ""
|
|
77
|
-
echo "⢠Follow redirects while maintaining cookies:"
|
|
78
|
-
echo ' curl -L \\'
|
|
79
|
-
echo ' -H "Cookie: $(get-cookie --url https://example.com/dashboard --render)" \\'
|
|
80
|
-
echo ' https://example.com/dashboard'
|
|
81
|
-
|
|
82
|
-
echo ""
|
|
83
|
-
echo "4ļøā£ Advanced Usage:"
|
|
84
|
-
echo "āāāāāāāāāāāāāāāāā"
|
|
85
|
-
|
|
86
|
-
# Show what cookies would be sent for different URLs
|
|
87
|
-
echo "⢠Preview cookies for different URLs:"
|
|
88
|
-
for url in "https://github.com/" "https://api.github.com/" "https://gist.github.com/"; do
|
|
89
|
-
COOKIE_COUNT=$(get-cookie --url "$url" --output json 2>/dev/null | jq 'length // 0')
|
|
90
|
-
echo " $url ā $COOKIE_COUNT cookies"
|
|
91
|
-
done
|
|
92
|
-
|
|
93
|
-
echo ""
|
|
94
|
-
echo "5ļøā£ Shell Function for Your .bashrc/.zshrc:"
|
|
95
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
96
|
-
cat << 'EOF'
|
|
97
|
-
# Add to your shell config for easy authenticated requests
|
|
98
|
-
auth_curl() {
|
|
99
|
-
local url=$1
|
|
100
|
-
shift
|
|
101
|
-
curl -H "Cookie: $(get-cookie --url "$url" --render 2>/dev/null)" "$@" "$url"
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
# Usage: auth_curl https://github.com/settings/profile -s | grep username
|
|
105
|
-
EOF
|
|
106
|
-
|
|
107
|
-
echo ""
|
|
108
|
-
echo "6ļøā£ Comparison: Manual vs --url flag:"
|
|
109
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
110
|
-
echo "ā Manual (need to know domain and cookie names):"
|
|
111
|
-
echo ' get-cookie user_session github.com --render'
|
|
112
|
-
echo ""
|
|
113
|
-
echo "ā
With --url (automatic):"
|
|
114
|
-
echo ' get-cookie --url https://github.com/settings/profile --render'
|
|
115
|
-
echo ""
|
|
116
|
-
echo "The --url flag automatically:"
|
|
117
|
-
echo " ⢠Extracts the domain from the URL"
|
|
118
|
-
echo " ⢠Gets ALL relevant cookies for that domain"
|
|
119
|
-
echo " ⢠Handles subdomains correctly"
|
|
120
|
-
echo " ⢠Returns cookies in the right format for curl"
|
|
121
|
-
|
|
122
|
-
echo ""
|
|
123
|
-
echo "7ļøā£ Real Example - Download your GitHub avatar:"
|
|
124
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
125
|
-
USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2 | cut -d';' -f1)
|
|
126
|
-
if [ -n "$USERNAME" ]; then
|
|
127
|
-
echo "Downloading avatar for: $USERNAME"
|
|
128
|
-
echo "Command:"
|
|
129
|
-
echo " curl -H \"Cookie: \$(get-cookie --url https://github.com/$USERNAME.png --render)\" \\"
|
|
130
|
-
echo " -o avatar.png https://github.com/$USERNAME.png"
|
|
131
|
-
else
|
|
132
|
-
echo "Not logged into GitHub"
|
|
133
|
-
fi
|
|
134
|
-
|
|
135
|
-
echo ""
|
|
136
|
-
echo "ā
The --url flag makes cookie extraction automatic and foolproof!"
|
|
@@ -1,110 +0,0 @@
|
|
|
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!"
|
|
@@ -1,115 +0,0 @@
|
|
|
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."
|
package/examples/github-api.sh
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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!"
|
|
@@ -1,118 +0,0 @@
|
|
|
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."
|