@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.
@@ -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
@@ -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!"