LeetCode-OpenSource / vscode-leetcode

Solve LeetCode problems in VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-leetcode
MIT License
8.23k stars 651 forks source link

Failed to log in with a leetcode.com account #478

Open queensferryme opened 5 years ago

queensferryme commented 5 years ago

🐛 Bug Report

I can't log into my leetcode.com account via vscode plugin, but I can log in with the same email & password in the browser. In contrast, my leetcode-cn.com account seems to work fine with this vscode plugin.

To Reproduce

None

Expected behavior

Log into my leetcode.com account.

Extension Output

login:  Active  Name               Version         Desc
----------------------------------------------------------------------------------------------------
   ✔     solution.discuss   2019.02.03      Plugin to fetch most voted solution in discussions.
   ✔     company            2017.12.18      Plugin to query by company for free user.
   ✔     cache              default         Plugin to provide local cache.
   ✔     retry              default         Plugin to retry last failed request if autologin.enable is on.
   ✘     leetcode.cn        2018.11.25      Plugin to talk with leetcode-cn APIs.
   ✔     leetcode           default         Plugin to talk with leetcode APIs.
[ERROR] You are not login yet?
login: pass: - Signing in leetcode.com
[ERROR] invalid password?

Your Environment

queensferryme commented 5 years ago

I am afraid this is an issue with the upstream project leetcode-cli.

image

eeliu commented 5 years ago

+1

eeliu commented 5 years ago

How to make it works? Anyone, please help us.

mpirbhoy commented 5 years ago

+1

zhoujf620 commented 5 years ago

I have the same problem that I switched to leetcode-cn endpoint yesterday but cannot login my leetcode account anymore. I have tried to use the mobile's hotpot and vpn global mode, still failed.

Is there any solution to solve this problem?

P.S. reinstalling cannot solve this.

Extension Output

login: login: Active Name Version Desc

✘ solution.discuss 2019.02.03 Plugin to fetch most voted solution in discussions. ✘ company 2017.12.18 Plugin to query by company for free user. ✔ cache default Plugin to provide local cache. ✔ retry default Plugin to retry last failed request if autologin.enable is on. ✘ leetcode.cn 2018.11.25 Plugin to talk with leetcode-cn APIs. ✔ leetcode default Plugin to talk with leetcode APIs. /Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/yargs/yargs.js:1148 else throw err ^

TypeError: Cannot read property 'toString' of undefined at /Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/log.js:55:31 at Array.map () at Object.log. [as info] (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/log.js:55:20) at Object.cmd.handler (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/commands/user.js:59:11) at Object.runCommand (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/yargs/lib/command.js:238:44) at Object.parseArgs [as _parseArgs] (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/yargs/yargs.js:1063:30) at Object.get [as argv] (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/yargs/yargs.js:1004:21) at runCommand (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/cli.js:86:5) at /Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/cli.js:103:5 at initPlugins (/Users/albert/.vscode/extensions/shengchen.vscode-leetcode-0.15.7/node_modules/vsc-leetcode-cli/lib/cli.js:64:12) login: pass: - Signing in leetcode.com [ERROR] invalid password?

tcwtc commented 5 years ago

same issue

BaccanoEva commented 5 years ago

+1

qiwei9743 commented 5 years ago

+1

Kalyan-M commented 5 years ago

+1

yihong0618 commented 5 years ago

Seems the same prblems. I try to locate it, one may cause the problem is that the leetcode.com use the recaptcha_token for now. And the code in leetcode-cli doesn't have it.

222

But the leetcode-cn's payload is as usual. image

And the leetcode-cli's login payload is like below. image

I think may use another way to login and get the session or solve the recaptcha.

@jdneo @queensferryme

RushviShah commented 5 years ago

+1

Vigoose commented 5 years ago

same issue

LincolnZeng commented 5 years ago

same bug here, can not login while same username and pw are working fine on leetcode website

zzjoey commented 5 years ago

+1, the same issue.

oasis10702 commented 5 years ago

+1, same issue

Holybasil commented 5 years ago

same

jdneo commented 5 years ago

Hi @all,

Sorry I'm busying with my work these days. Hope we could have volunteers who are interested to provide fixed in the upstream repo: https://github.com/leetcode-tools/leetcode-cli

yihong0618 commented 5 years ago

Hi @jdneo

I try to fix the problems in leetcode-cli

But leetcode.com use recaptcha which is hard to generate the token when use post to login. Also I try to use puppeteer to login and get session but the recaptcha also exists.

Now I think two ways maybe can avoid it for now , Because the recaptcha only used in login api, others were not affected.

  1. open the session method to help user to store(which can get in chrome ) in vscode leetcode session
  2. use third-party to login (such as github) and get the session But these ways are not simple and elegant.

    I am still trying other ways And for now, the leetcode-cn doesn't add the recaptcha, everyone can try it (dump data from leetcode to leetcode-cn) and select leetcode-cn in vscode-leetcode Hope someone have a better way to fix it.

Thank you

jdneo commented 5 years ago

@yihong0618 Thank you for the great effort! I guess if leetcode has applied the recaptcha token. leetcode-cn will finally migrate to it in some time. Hope we can find a way to resolve it.

Thank you again!

glucas350 commented 5 years ago

+1

CoolersCoder commented 5 years ago

@jdneo 登录页https://leetcode.com/accounts/login/ 首次登陆会生成一个 id名为recaptcha-token,这个就是@yihong0618 说的谷歌的https://www.google.com/recaptcha/intro/v3.html

每次用户登陆的时候貌似都要检查一下这个hidden的value. 有没有办法存储在plugin临时文件里? 因为没有开发过plugin不清楚是否可行。

<input id="recaptcha-token" type="hidden" value="03AOLTBLRLMf9Mib_S4ixPeHd9qQQjEpPRvs1NVhsWvJogjBEZriWO-0L58e5Umzd3b5l98t2vW2s532-jSRqQRr23lZuJSx_PyClRRIjK4Wjv6pUh5pafJRvLLYTZqMbJ3JtiwlohtKDiggB6yYqsFZNY_t8IDnHlWKivV4SvW6nCSGjg4aFGTfySip7QlUQv5N54E_V4BmmffNoLrEr2tMgiODzSCy7TbA9rUHO4RbI30HQsF4sZt9pGk3u2RbUaeNxDWqyxeTuvPOrz8LgNoOeST142GkHHoCiVwbFcm1lPDBLizIbKpf77YwNdg0FhtqJq1SJcq35PniBEdEMH8EMB_kH2KJcTK51_X_cqUH2ddOzMxwoMPn95lQn5m7w3UjKPUxI-zAKDRtEook66jJK3TNwT7QdTK3edZjNs1znypTgA0Et3kO8">
const opts = {
      url: config.sys.urls.login,
      headers: {
        Origin: config.sys.urls.base,
        Referer: config.sys.urls.login,
        Cookie: 'csrftoken=' + user.loginCSRF + ';'
      },
      form: {
        csrfmiddlewaretoken: user.loginCSRF,
        login: user.login,
        password: user.pass
       //probably here, we might need one more recaptcha-token
      }
};
yihong0618 commented 5 years ago

@CoolersCoder Thank you very much for your help. This value is generate by google-recaptcha, and will also check if you are a robot, so use puppeteer will call a robot check, so this value can't store. And I still not find an easy to slove this, sad.

lostindark commented 5 years ago

This problem is a little bit tricky. Recaptcha is hard to deal without a browser. I can think of 2 ways to fix this:

  1. Host the login page in an embedded browser, and extract session token when login finishes. puppeteer?
  2. If leetcode supports OAuth2 (I don't know as I can't find any document of leetcode API), the plugin can host a client app and use browser to login. Once login finishes and the plugin can get the token for leetcode API.

None of these are simple, maybe we should talk to leetcode and see if there are any support way of login for plugins?

jdneo commented 5 years ago

@lostindark Thank you, I'll try to reach leetcode recently. But I'm not sure who should be talked to. If anyone knows, please let me know.

yihong0618 commented 5 years ago

@jdneo @lostindark

  1. I had tried to use puppeteer but using puppeteer will cause a rotbot check problem.
  2. And the sencond way I also do my best to try but faild, and I happend to find that leetcode is beta their app, maybe we can try to get some luck

    @jdneo

  3. I have try to session login that user can copy the cookie from chrome(or others) then paste to the vscode input field, one time login then all the others features are not affected so the user can use vscode-leetcode as usual, can I compelete it and pull request for short-term solution ?

The demo will be like below (user can only copy the cookie and vscode-cli will parser it ): image

image

This cookie but need to add some guide。 image

lostindark commented 5 years ago

@yihong0618 Have you tried to turn headless off?

const browser = await puppeteer.launch({
  headless: false
})

The other way to try is to set a normal chrome user agent and see if that works. await page.setUserAgent(<valid chrome user agent>)

yihong0618 commented 5 years ago

@lostindark Yes, Also cause the check robot, and it seems that it counts your score to test if you are human. Then I gave up this method.

zentby commented 5 years ago

Is there a way to paste the cookies from browser into the extension? So it doesn't have to automate the login process. @jdneo

victor886 commented 5 years ago

@jdneo @lostindark

  1. I had tried to use puppeteer but using puppeteer will cause a rotbot check problem.
  2. And the sencond way I also do my best to try but faild, and I happend to find that leetcode is beta their app, maybe we can try to get some luck

@jdneo

  1. I have try to session login that user can copy the cookie from chrome(or others) then paste to the vscode input field, one time login then all the others features are not affected so the user can use vscode-leetcode as usual, can I compelete it and pull request for short-term solution ?

The demo will be like below (user can only copy the cookie and vscode-cli will parser it ): image

image

This cookie but need to add some guide。 image

hi big god, I am newbee to vscode. Any step-by-step instructions to solve the problem temporily ? thanks!

playmyswift commented 5 years ago

in my app, I use load webview to fixed it(webview need user login, then save the cookie)

victor886 commented 5 years ago

in my app, I use load webview to fixed it(webview need user login, then save the cookie)

how to load webview in vs code?

jdneo commented 5 years ago

Hi @ericjjj,

Would you mind to explain more about your solution?

Thanks.

prorigorous commented 5 years ago

same bug here, can not login while same username and pw are working well on leetcode.com website. Login leetcode-cn.com are work well via vscode and website.

playmyswift commented 5 years ago

@jdneo @victor886 I'm sorry about my solution not clear, my app is a leetcode ios client, and it can open a webview to load login page, then check login status, save the cookie,

I think vscode solution, Should let user copy their cookie

yihong0618 commented 5 years ago

@victor886 the solution is not simple. Maybe you can wait for @jdneo's update. I think the best way for now is using leetcode-cn (you can trans your data from leetcode.com), the leetcode-cn works well. And because of our "GFW", I think they will not add recaptcha so soon(need google api). And I just add "user -c" method in leetcode-cli you can also use that. You can login leetcode with chrome and press F12, click->network->XHR and you could see your cookie as below image

victor886 commented 5 years ago

@yihong0618

thanks, in my case ,leetcode-cn also not works well. I dont know the reason.Does your leetcode-cli approach needs to install the leetcode-cli beside this extesion ? then login with cookie get from browser? can you tell me a little more detail instructioin. thanks a lot.

Cering commented 5 years ago

a simple way to login is reuse chrome's cookie first login leetcode's account in chrome browser and then:

leetcode-cli.exe plugin -e cookie.chrome
 Active  Name               Version         Desc
----------------------------------------------------------------------------------------------------
   √     solution.discuss   2019.02.03      Plugin to fetch most voted solution in discussions.
   √     company            2017.12.18      Plugin to query by company for free user.
   ×     cpp.lint           2017.07.27      Plugin to do static code check on c++ code.
   ×     cpp.run            2017.07.29      Plugin to run cpp code locally for debugging.
   ×     github             2018.11.18      Plugin to commit accepted code to your own github repo.
   √     cache              default         Plugin to provide local cache.
   √     retry              default         Plugin to retry last failed request if autologin.enable is on.
   ×     leetcode.cn        2018.11.25      Plugin to talk with leetcode-cn APIs.
   ×     lintcode           2018.11.18      Plugin to talk with lintcode APIs.
   √     cookie.chrome      2018.11.18      Plugin to reuse Chrome's leetcode cookie.
   ×     cookie.firefox     2018.11.19      Plugin to reuse firefox's leetcode cookie.
   √     leetcode           default         Plugin to talk with leetcode APIs.

when login with leetcode-cli, just input any login and pass:

leetcode-cli.exe user -l
login: 123
pass: 123
Successfully login as Cering

However, another problem is that leetcode may had changed its api. So when you try submit or test by leetcode-cli , it will stuck in

leetcode-cli.exe test 1.two-sum.py

Input data:
[2,7,11,15]
9
\ Waiting for judge result

FOREVER ...

yihong0618 commented 5 years ago

@Cering There are two steps to get the cookie

  1. Login
  2. Call any api (such as click the problems button) not only get the leetcode session but also you need to get the csrf token. Because you have no csrf token you can only get the problems and your profile. As below: image
jzbuaa commented 5 years ago

image still not working, I installed the latest vsc-leetcode-cli and copied the whole cookie, is it supposed to be used like this?

victor886 commented 5 years ago

@yihong0618 I tried leetcode-cli, also got info same with @jzbuaa ... can you tell us detail info?

yihong0618 commented 5 years ago

@victor886 @jzbuaa @jdneo Because the leetcode-cli default plugin is leetcode.cn now. You should do these things to solve this problem;

  1. cli: leetcode-cli user -L (big L) to logout
  2. Delete default plugin from leetcode.cn cli: leetcode-cli plugin -d leetcode.cn(delete leetcode.cn)
  3. Change default to leetcode cli: leetcode-cli plugin -e leetcode

image

image image

image

Hope help you

jzbuaa commented 5 years ago

@yihong0618 works perfectly, thank you very much.

another question is, when will the cookie expire? in other words, how often do I need to paste the cookie in leetcode-cli?

yihong0618 commented 5 years ago

@jzbuaa I think maybe over a month. As we login vscode-leetcode before, we never need to re-login (the way to save leetcode-session never changed).

victor886 commented 4 years ago

@yihong0618 thanks a lot, I also work around with your version of leetcode-cli, looking forward @jdneo updates (maybe depend on vscode's webview api to load a leetcode's webpage and manually login?). Besides, leetcode-cn does works fine with current plugin, it requires to create a new account, I used to assume the account can be reused...sorry!

jdneo commented 4 years ago

@victor886 VS Code's webview API is not suitable for this since as far as I know it does not support reading the local storage/cookie.

victor886 commented 4 years ago

@yihong0618 leetcode cookieIn is your new command excepet leetcode user -c? so after merged , I should run npm update to get this command?

yihong0618 commented 4 years ago

@victor886
No, that change is in vscode-leetcode~

nosensezzz commented 4 years ago

why I am getting 'Error: You are not login yet?' when I tried to cookie login with 'leetcode user -c'?

did the new command has been added to npm already?

OH, just saw the change is only in vscode-leetcode, but I didn't find that where we could run command in vscode-leetcode, do we have a leetcode-cli in vscode?

mrjihai commented 4 years ago

+1 same issue

yihong0618 commented 4 years ago

@nosensezzz it is not updated in vscode-leetcode