@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
|
-
# Test GitHub authentication with improved expired cookie filtering
|
|
4
|
-
echo "š Testing GitHub Authentication with Improved Cookie Filtering"
|
|
5
|
-
echo "=============================================================="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# Method 1: Using --url and --render (the recommended pattern)
|
|
9
|
-
echo "Method 1: Using --url and --render (default filtering)"
|
|
10
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
11
|
-
|
|
12
|
-
# Get cookies for GitHub settings
|
|
13
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
|
|
14
|
-
echo "Cookie string length: $(echo "$COOKIES" | wc -c) characters"
|
|
15
|
-
|
|
16
|
-
# Test authentication
|
|
17
|
-
echo -n "Testing authentication: "
|
|
18
|
-
RESPONSE=$(curl -s -L \
|
|
19
|
-
-H "Cookie: $COOKIES" \
|
|
20
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
|
|
21
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
22
|
-
"https://github.com/settings/profile")
|
|
23
|
-
|
|
24
|
-
if echo "$RESPONSE" | grep -q "Sign in to GitHub"; then
|
|
25
|
-
echo "ā Not authenticated (redirected to login)"
|
|
26
|
-
elif echo "$RESPONSE" | grep -q "Your profile"; then
|
|
27
|
-
echo "ā
Authenticated! (settings page accessed)"
|
|
28
|
-
else
|
|
29
|
-
TITLE=$(echo "$RESPONSE" | grep -o "<title>[^<]*</title>" | head -1)
|
|
30
|
-
echo "ā¹ļø Page title: $TITLE"
|
|
31
|
-
fi
|
|
32
|
-
echo ""
|
|
33
|
-
|
|
34
|
-
# Method 2: With --include-expired to see the difference
|
|
35
|
-
echo "Method 2: With --include-expired flag"
|
|
36
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
37
|
-
|
|
38
|
-
COOKIES_WITH_EXPIRED=$(get-cookie --url https://github.com/settings/profile --render --include-expired 2>/dev/null)
|
|
39
|
-
echo "Cookie string length: $(echo "$COOKIES_WITH_EXPIRED" | wc -c) characters"
|
|
40
|
-
|
|
41
|
-
# Compare cookie counts
|
|
42
|
-
DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
|
|
43
|
-
EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
|
|
44
|
-
|
|
45
|
-
echo "Cookies comparison:"
|
|
46
|
-
echo " ⢠Without --include-expired: $DEFAULT_COUNT cookies"
|
|
47
|
-
echo " ⢠With --include-expired: $EXPIRED_COUNT cookies"
|
|
48
|
-
|
|
49
|
-
if [ "$EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
|
|
50
|
-
DIFF=$((EXPIRED_COUNT - DEFAULT_COUNT))
|
|
51
|
-
echo " ⢠ā
Filtered out $DIFF expired cookies"
|
|
52
|
-
else
|
|
53
|
-
echo " ⢠ā¹ļø No expired cookies to filter (all cookies are valid)"
|
|
54
|
-
fi
|
|
55
|
-
echo ""
|
|
56
|
-
|
|
57
|
-
# Method 3: Smart filtering for valid session cookies
|
|
58
|
-
echo "Method 3: JSON filtering for valid cookies"
|
|
59
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
60
|
-
|
|
61
|
-
# Get valid session cookie (filter by length and expiry)
|
|
62
|
-
VALID_SESSION=$(get-cookie --url https://github.com --output json 2>/dev/null | \
|
|
63
|
-
jq -r '.[] | select(.name == "user_session" and (.value | length) > 20) | .value' | \
|
|
64
|
-
head -1)
|
|
65
|
-
|
|
66
|
-
if [ -n "$VALID_SESSION" ]; then
|
|
67
|
-
echo "ā
Found valid session cookie: ${VALID_SESSION:0:20}... (${#VALID_SESSION} chars)"
|
|
68
|
-
|
|
69
|
-
# Build cookie header
|
|
70
|
-
COOKIE_HEADER="user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION"
|
|
71
|
-
|
|
72
|
-
# Test authentication
|
|
73
|
-
echo -n "Testing with filtered session: "
|
|
74
|
-
AUTH_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
75
|
-
-H "Cookie: $COOKIE_HEADER" \
|
|
76
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
77
|
-
"https://github.com/settings/profile")
|
|
78
|
-
|
|
79
|
-
if [ "$AUTH_CODE" = "200" ]; then
|
|
80
|
-
echo "ā
Authenticated (HTTP 200)"
|
|
81
|
-
else
|
|
82
|
-
echo "ā Not authenticated (HTTP $AUTH_CODE)"
|
|
83
|
-
fi
|
|
84
|
-
else
|
|
85
|
-
echo "ā No valid session cookie found"
|
|
86
|
-
fi
|
|
87
|
-
echo ""
|
|
88
|
-
|
|
89
|
-
# Final test: Access private content
|
|
90
|
-
echo "Final Test: Accessing Private Repository List"
|
|
91
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
92
|
-
|
|
93
|
-
# Try to get username from cookies
|
|
94
|
-
USERNAME=$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)
|
|
95
|
-
|
|
96
|
-
if [ -n "$USERNAME" ]; then
|
|
97
|
-
echo "Username detected: $USERNAME"
|
|
98
|
-
|
|
99
|
-
# Get repository list with authentication
|
|
100
|
-
REPOS_HTML=$(curl -s -L \
|
|
101
|
-
-H "Cookie: $(get-cookie --url https://github.com/$USERNAME --render)" \
|
|
102
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
103
|
-
"https://github.com/$USERNAME?tab=repositories")
|
|
104
|
-
|
|
105
|
-
# Count visible repositories
|
|
106
|
-
PUBLIC_COUNT=$(echo "$REPOS_HTML" | grep -o '>Public<' | wc -l | xargs)
|
|
107
|
-
PRIVATE_COUNT=$(echo "$REPOS_HTML" | grep -o '>Private<' | wc -l | xargs)
|
|
108
|
-
|
|
109
|
-
echo "Repository visibility:"
|
|
110
|
-
echo " ⢠Public repositories: $PUBLIC_COUNT"
|
|
111
|
-
echo " ⢠Private repositories: $PRIVATE_COUNT"
|
|
112
|
-
|
|
113
|
-
if [ "$PRIVATE_COUNT" -gt 0 ]; then
|
|
114
|
-
echo " ⢠ā
Can see private repositories!"
|
|
115
|
-
else
|
|
116
|
-
echo " ⢠ā ļø No private repositories visible"
|
|
117
|
-
fi
|
|
118
|
-
else
|
|
119
|
-
echo "ā Could not detect username from cookies"
|
|
120
|
-
fi
|
|
121
|
-
echo ""
|
|
122
|
-
|
|
123
|
-
echo "š” Summary:"
|
|
124
|
-
echo "āāāāāāāāā"
|
|
125
|
-
echo "⢠Default behavior filters expired cookies for better success"
|
|
126
|
-
echo "⢠Use --include-expired to include all cookies (debugging)"
|
|
127
|
-
echo "⢠For best results: get-cookie --url <URL> --render"
|
|
128
|
-
echo "⢠Some browsers may store invalid cookies that need filtering"
|
|
129
|
-
echo ""
|
|
130
|
-
|
|
131
|
-
# Check if the feature is making a difference
|
|
132
|
-
if [ "$DEFAULT_COUNT" -eq "$EXPIRED_COUNT" ]; then
|
|
133
|
-
echo "ā¹ļø Note: Currently all cookies are valid (no expired cookies found)"
|
|
134
|
-
else
|
|
135
|
-
echo "ā
Expired cookie filtering is improving authentication!"
|
|
136
|
-
fi
|
package/examples/working-curl.sh
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Working example: Using get-cookie with curl for web scraping
|
|
4
|
-
echo "š Web Scraping with get-cookie + curl"
|
|
5
|
-
echo "======================================="
|
|
6
|
-
|
|
7
|
-
# Example 1: Check if logged into GitHub (web, not API)
|
|
8
|
-
echo -e "\n1ļøā£ Checking GitHub login status (web)..."
|
|
9
|
-
GITHUB_COOKIES=$(get-cookie % github.com --render 2>/dev/null | head -1)
|
|
10
|
-
|
|
11
|
-
if [ -n "$GITHUB_COOKIES" ]; then
|
|
12
|
-
# Access the settings page which requires authentication
|
|
13
|
-
RESPONSE=$(curl -s -L \
|
|
14
|
-
-H "Cookie: $GITHUB_COOKIES" \
|
|
15
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
16
|
-
"https://github.com/settings/profile" | grep -o '<input.*name="user\[profile_name\]".*value="[^"]*"' | sed 's/.*value="\([^"]*\)".*/\1/')
|
|
17
|
-
|
|
18
|
-
if [ -n "$RESPONSE" ]; then
|
|
19
|
-
echo " ā
Successfully accessed GitHub settings"
|
|
20
|
-
echo " Profile name field found: $RESPONSE"
|
|
21
|
-
else
|
|
22
|
-
echo " ā ļø Could not access settings (may need more cookies)"
|
|
23
|
-
fi
|
|
24
|
-
else
|
|
25
|
-
echo " ā No GitHub cookies found"
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
# Example 2: Download a file that requires login
|
|
29
|
-
echo -e "\n2ļøā£ Example: Download private content..."
|
|
30
|
-
echo " Command to download a private gist:"
|
|
31
|
-
echo " curl -H \"Cookie: \$(get-cookie % github.com --render)\" -o gist.txt https://gist.github.com/username/gist_id/raw"
|
|
32
|
-
|
|
33
|
-
# Example 3: Check login status on various sites
|
|
34
|
-
echo -e "\n3ļøā£ Checking login status on popular sites..."
|
|
35
|
-
|
|
36
|
-
check_site_login() {
|
|
37
|
-
local domain=$1
|
|
38
|
-
local check_url=$2
|
|
39
|
-
local check_string=$3
|
|
40
|
-
|
|
41
|
-
echo -n " $domain: "
|
|
42
|
-
|
|
43
|
-
COOKIES=$(get-cookie % "$domain" --render 2>/dev/null | head -1)
|
|
44
|
-
if [ -z "$COOKIES" ]; then
|
|
45
|
-
echo "No cookies found"
|
|
46
|
-
return
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
# Try to access a page that requires login
|
|
50
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
51
|
-
-H "Cookie: $COOKIES" \
|
|
52
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
53
|
-
"$check_url")
|
|
54
|
-
|
|
55
|
-
if [ "$HTTP_CODE" = "200" ]; then
|
|
56
|
-
echo "ā
Logged in (HTTP 200)"
|
|
57
|
-
elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
|
|
58
|
-
echo "ā ļø Redirected (HTTP $HTTP_CODE) - possibly logged out"
|
|
59
|
-
else
|
|
60
|
-
echo "ā Not accessible (HTTP $HTTP_CODE)"
|
|
61
|
-
fi
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
check_site_login "github.com" "https://github.com/settings/profile" "Settings"
|
|
65
|
-
check_site_login "stackoverflow.com" "https://stackoverflow.com/users/edit/current" "Edit Profile"
|
|
66
|
-
check_site_login "linkedin.com" "https://www.linkedin.com/in/me/" "Profile"
|
|
67
|
-
|
|
68
|
-
# Example 4: Practical scraping example
|
|
69
|
-
echo -e "\n4ļøā£ Practical example: Get your GitHub stats..."
|
|
70
|
-
if [ -n "$GITHUB_COOKIES" ]; then
|
|
71
|
-
# Get the user's contribution graph data
|
|
72
|
-
USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2)
|
|
73
|
-
if [ -n "$USERNAME" ]; then
|
|
74
|
-
echo " Fetching contribution data for: $USERNAME"
|
|
75
|
-
|
|
76
|
-
# This would normally require being logged in to see private contributions
|
|
77
|
-
CONTRIBUTIONS=$(curl -s \
|
|
78
|
-
-H "Cookie: $GITHUB_COOKIES" \
|
|
79
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
80
|
-
"https://github.com/$USERNAME" | grep -o 'data-count="[0-9]*"' | head -7 | sed 's/data-count="\([0-9]*\)"/\1/')
|
|
81
|
-
|
|
82
|
-
if [ -n "$CONTRIBUTIONS" ]; then
|
|
83
|
-
echo " Recent contribution counts:"
|
|
84
|
-
echo "$CONTRIBUTIONS" | head -7 | while read count; do
|
|
85
|
-
echo " ⢠$count contributions"
|
|
86
|
-
done
|
|
87
|
-
fi
|
|
88
|
-
fi
|
|
89
|
-
fi
|
|
90
|
-
|
|
91
|
-
# Example 5: Advanced - Using with jq for JSON APIs that accept cookies
|
|
92
|
-
echo -e "\n5ļøā£ One-liner examples for common tasks:"
|
|
93
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
94
|
-
cat << 'EOF'
|
|
95
|
-
# Download all cookies as JSON for backup:
|
|
96
|
-
get-cookie % github.com --output json > github-cookies-backup.json
|
|
97
|
-
|
|
98
|
-
# Use with wget instead of curl:
|
|
99
|
-
wget --no-cookies --header "Cookie: $(get-cookie % example.com --render)" https://example.com/file
|
|
100
|
-
|
|
101
|
-
# Chain multiple domains:
|
|
102
|
-
(get-cookie % site1.com --render; get-cookie % site2.com --render) | curl -H "Cookie: $(cat)" https://api.example.com
|
|
103
|
-
|
|
104
|
-
# Use with httpie (more user-friendly than curl):
|
|
105
|
-
http GET https://example.com Cookie:"$(get-cookie % example.com --render)"
|
|
106
|
-
|
|
107
|
-
# Quick login check:
|
|
108
|
-
get-cookie logged_in github.com --render && echo "ā
Logged in" || echo "ā Not logged in"
|
|
109
|
-
EOF
|
|
110
|
-
|
|
111
|
-
echo -e "\nš Notes:"
|
|
112
|
-
echo "⢠The --render flag outputs: name1=value1; name2=value2"
|
|
113
|
-
echo "⢠Perfect for curl's Cookie header"
|
|
114
|
-
echo "⢠Works with any site that uses cookie authentication"
|
|
115
|
-
echo "⢠Remember: GitHub's API uses tokens, not cookies"
|
|
116
|
-
|
|
117
|
-
echo -e "\nā
Examples complete!"
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Working GitHub authentication with get-cookie
|
|
4
|
-
# This shows how to handle real-world cookie issues
|
|
5
|
-
|
|
6
|
-
echo "š Working GitHub Authentication with get-cookie"
|
|
7
|
-
echo "==============================================="
|
|
8
|
-
echo ""
|
|
9
|
-
|
|
10
|
-
# Method 1: Using --url and --render with validation
|
|
11
|
-
echo "Method 1: Smart cookie filtering"
|
|
12
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
13
|
-
|
|
14
|
-
# Get cookies and filter out invalid ones (too short)
|
|
15
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --output json 2>/dev/null | \
|
|
16
|
-
jq -r '.[] | select(.name == "user_session" and (.value | length) > 10) | "\(.name)=\(.value)"' | \
|
|
17
|
-
head -1)
|
|
18
|
-
|
|
19
|
-
if [ -n "$COOKIES" ]; then
|
|
20
|
-
echo "ā
Found valid session cookie"
|
|
21
|
-
|
|
22
|
-
# Add the same-site cookie
|
|
23
|
-
COOKIES="$COOKIES; __Host-user_session_same_site=${COOKIES#*=}"
|
|
24
|
-
|
|
25
|
-
echo "Testing authentication..."
|
|
26
|
-
TITLE=$(curl -s -L \
|
|
27
|
-
-H "Cookie: $COOKIES" \
|
|
28
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
29
|
-
"https://github.com/settings/profile" | \
|
|
30
|
-
grep -o "<title>[^<]*</title>" | head -1)
|
|
31
|
-
|
|
32
|
-
if echo "$TITLE" | grep -q "Your profile"; then
|
|
33
|
-
echo "ā
Successfully authenticated!"
|
|
34
|
-
else
|
|
35
|
-
echo "ā Not authenticated: $TITLE"
|
|
36
|
-
fi
|
|
37
|
-
else
|
|
38
|
-
echo "ā No valid session cookies found"
|
|
39
|
-
fi
|
|
40
|
-
|
|
41
|
-
echo ""
|
|
42
|
-
echo "Method 2: Direct approach with validation"
|
|
43
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
44
|
-
|
|
45
|
-
# Function to get valid cookies only
|
|
46
|
-
get_valid_cookie() {
|
|
47
|
-
local cookie_name=$1
|
|
48
|
-
local domain=$2
|
|
49
|
-
local min_length=${3:-10} # Minimum valid length
|
|
50
|
-
|
|
51
|
-
get-cookie "$cookie_name" "$domain" --output json 2>/dev/null | \
|
|
52
|
-
jq -r --arg min "$min_length" \
|
|
53
|
-
'.[] | select(.value | length > ($min | tonumber)) | .value' | \
|
|
54
|
-
head -1
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Get a valid session
|
|
58
|
-
VALID_SESSION=$(get_valid_cookie "user_session" "github.com" 20)
|
|
59
|
-
|
|
60
|
-
if [ -n "$VALID_SESSION" ]; then
|
|
61
|
-
echo "ā
Found valid session: ${VALID_SESSION:0:20}... (truncated)"
|
|
62
|
-
|
|
63
|
-
# Test with curl
|
|
64
|
-
curl -s -I \
|
|
65
|
-
-H "Cookie: user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION" \
|
|
66
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
67
|
-
"https://github.com/settings/profile" | head -1
|
|
68
|
-
else
|
|
69
|
-
echo "ā No valid session found"
|
|
70
|
-
fi
|
|
71
|
-
|
|
72
|
-
echo ""
|
|
73
|
-
echo "Method 3: The Ultimate One-Liner"
|
|
74
|
-
echo "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"
|
|
75
|
-
echo ""
|
|
76
|
-
echo "# Get valid cookies and access private content:"
|
|
77
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://github.com --output json | jq -r '"'"'.[] | select(.name == "user_session" and (.value | length) > 20) | "\(.name)=\(.value)"'"'"' | head -1)" https://github.com/settings/profile'
|
|
78
|
-
echo ""
|
|
79
|
-
|
|
80
|
-
echo "š” Key Insights:"
|
|
81
|
-
echo "āāāāāāāāāāāāāā"
|
|
82
|
-
echo "⢠Some browsers store truncated/invalid cookies"
|
|
83
|
-
echo "⢠Filter cookies by value length for validity"
|
|
84
|
-
echo "⢠GitHub needs both user_session and __Host-user_session_same_site"
|
|
85
|
-
echo "⢠The new --include-expired flag helps debug cookie issues"
|
|
86
|
-
echo ""
|
|
87
|
-
echo "ā
With proper filtering, get-cookie works perfectly for authentication!"
|