@mherod/get-cookie 4.4.1 → 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,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!"