skygragon / leetcode-cli

A cli tool to enjoy leetcode!
MIT License
3.64k stars 457 forks source link

Session expiring immediately after login #86

Open Rich86man opened 6 years ago

Rich86man commented 6 years ago

Every time after entering my login credentials I get [ERROR] session expired, please login again [-1]

〉./bin/leetcode version -v


| | | | | | | | | |_ | | _ | |/ \/ \ |/ _|/ \ / ` |/ \ | | / / |_ (| () | (| | / ||\|_|_|\|_/ _,|_| CLI v2.5.1

[Environment] Node v8.9.1 OS darwin 17.3.0 Cache /Users/kirk/.lc/cache Config /Users/kirk/.lc/config.json

[Configuration] autologin {"enable":false,"retry":2} code {"editor":"vim","lang":"cpp"} color {"enable":true,"theme":"default"} icon {"theme":""} network {"concurrency":10}

[Themes] Colors blue,dark,default,molokai,orange,pink,solarized,solarized.light Icons ascii,default,win7

[Plugins] cache default retry default leetcode default

HEAD : 1cee26c47006aafc13393b5221f927b7de0f3e05

skygragon commented 6 years ago

@Rich86man could you try following to print more logs?

leetcode user -l -vv
Rich86man commented 6 years ago
〉./bin/leetcode user -l -vv
[TRACE] initializing all plugins
[TRACE] found plugin: cache=default
[TRACE] inited plugin: cache
[TRACE] found plugin: leetcode=default
[TRACE] inited plugin: leetcode
[TRACE] found plugin: retry=default
[TRACE] inited plugin: retry
[TRACE] missing plugins: 0
login: my@email.com
pass:
[DEBUG] running leetcode.login
[DEBUG] running leetcode.signin
⠋ Signing in leetcode.com[TRACE] REQUEST %s { uri: 'https://leetcode.com/accounts/login/',
  callback: [Function] }
[TRACE] REQUEST %s make request https://leetcode.com/accounts/login/
⠹ Signing in leetcode.com[TRACE] REQUEST %s onRequestResponse https://leetcode.com/accounts/login/ 403 { date: 'Tue, 30 Jan 2018 02:26:41 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie':
   <hidden>,
  vary: 'Accept-Encoding',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '3e50fce0ae016dae-SJC' }
[TRACE] REQUEST %s reading response's body
[TRACE] REQUEST %s finish init function https://leetcode.com/accounts/login/
[TRACE] REQUEST %s response end https://leetcode.com/accounts/login/ 403 { date: 'Tue, 30 Jan 2018 02:26:41 GMT',
  'content-type': 'text/html; charset=utf-8',
  'transfer-encoding': 'chunked',
  connection: 'close',
  'set-cookie':
   <hidden>,
  vary: 'Accept-Encoding',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  'x-content-type-options': 'nosniff',
  'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  server: 'cloudflare',
  'cf-ray': '3e50fce0ae016dae-SJC' }
[TRACE] REQUEST %s end event https://leetcode.com/accounts/login/
[TRACE] REQUEST %s has body https://leetcode.com/accounts/login/ 162
[TRACE] REQUEST %s emitting complete https://leetcode.com/accounts/login/
[DEBUG] http error: 403
[ERROR] session expired, please login again [-1]
skygragon commented 6 years ago

@Rich86man are you able to open "https://leetcode.com/accounts/login/" in browser? sometimes leetcode.com would block you if you send to many requests in the same time.

leekaka commented 6 years ago

C:\Users\Lika\AppData\Roaming\npm\node_modules\leetcode-cli\lib\plugins\leetcode.js:461 user.hash = favorite.id_hash;

TypeError: Cannot read property 'id_hash' of undefined

when i try to login in ...

leekaka commented 6 years ago

Could you help me ...please..Thx very much!

Rich86man commented 6 years ago

I was able to open that page in my browser. I also reran the command to make sure that its still not working. This is a weird issue.

skygragon commented 6 years ago

@leekaka would appreciate if you could open another ticket to address your issue

@Rich86man it's weird your error occurred in the very beginning when cli sent the first GET request to "https://leetcode.com/accounts/login/", but 403 error returned. Please try add following code to lib/plugins/leetcode.js (around line 423):

request(config.sys.urls.login, function(e, resp, body) {
    spin.stop();
    console.log('body=' + body);  // <== add this line
    e = checkError(e, resp, 200);
    if (e) return cb(e);

This will print the error message returned from leetcode.com.

Rich86man commented 6 years ago
〉./bin/leetcode user -l
login: my@email.com
pass:
body=<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

[ERROR] session expired, please login again [-1]
skygragon commented 6 years ago

@Rich86man are u using any proxy in terminal? IMHO leetcode.com should have no "nginx" in the response.

Rich86man commented 6 years ago

I don't think so.

echo $http_proxy
echo $https_proxy

both came back with empty strings.

I opened terminal (I usually use iTerm) and made a profile with a blank bash_profile and bashrc. I got the same results.

Feel free to close this issue as a weird edge case. I'm sure this is just a side project for you, no need to spend a whole bunch of time on this.

skygragon commented 6 years ago

Does curl work as well?

curl -I https://leetcode.com/accounts/login/
Rich86man commented 6 years ago
〉curl -I https://leetcode.com/accounts/login/
HTTP/2 200
date: Thu, 01 Feb 2018 18:05:53 GMT
content-type: text/html; charset=utf-8
set-cookie: __cfduid=d67c672e7817fe908225c47456a5c1e741517508353; expires=Fri, 01-Feb-19 18:05:53 GMT; path=/; domain=.leetcode.com; HttpOnly
vary: Accept-Encoding
vary: Cookie
x-frame-options: SAMEORIGIN
set-cookie: csrftoken=ynX7g9w28OJM9Ign0msfKHSHFSPTVhrkV4GQX2gSPmToOFJm3Mrgx8jgTeT1ehpZ; expires=Thu, 31-Jan-2019 18:05:53 GMT; Max-Age=31449600; Path=/; secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 3e66d769cc936d00-SJC
skygragon commented 6 years ago

Here the suspicious one to me is HTTP/2. As far as I know some nodejs libraries don't support it well at the moment (e.g. request), not sure if it's your root cause.

duomu commented 6 years ago

@skygragon hi , I meet this problem too. and when I try "curl -I https://leetcode.com/accounts/login/", it responses "HTTP/1.1 403 Forbidden"

weinberggithub commented 5 years ago

it seems the issue not solved.