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

yhnedison commented 4 years ago

leetcode user -c is showing [ERROR] You are not login yet?. I installed most recent version of leetcode-cli. How to run this command correctly?

yihong0618 commented 4 years ago

@yhnedison

  1. make sure you have installed latest version leetcode-cli which is 2.6.17
  2. check the plugin point that you are using leetcode not leetcode.cn
  3. cli: leetcode-cli user -L (big L) to logout Delete default plugin from leetcode.cn cli: leetcode-cli plugin -d leetcode.cn(delete leetcode.cn) Change default to leetcode cli: leetcode-cli plugin -e leetcode

  4. leetcode-cli user -c
wanquanw commented 4 years ago

leetcode user -c is showing [ERROR] You are not login yet?. I installed most recent version of leetcode-cli. How to run this command correctly?

First use leetcode version to see if you are using the latest version. In the installation guide, note that the "From GitHub" Section gives another repo of leetcode-cli, whose master is 2.6.2. Uninstall your leetcode-cli and use npm install -g leetcode-tools/leetcode-cli to install the latest version (2.6.17).

yhnedison commented 4 years ago

@yhnedison

  1. make sure you have installed latest version leetcode-cli which is 2.6.17
  2. check the plugin point that you are using leetcode not leetcode.cn
  3. cli: leetcode-cli user -L (big L) to logout Delete default plugin from leetcode.cn cli: leetcode-cli plugin -d leetcode.cn(delete leetcode.cn) Change default to leetcode cli: leetcode-cli plugin -e leetcode

  4. leetcode-cli user -c

Thank you! It's working now!

For anyone wondering, please use https://github.com/leetcode-tools/leetcode-cli (instead of https://github.com/skygragon/leetcode-cli) and build from source to get 2.6.17 and follow the steps above.

nosensezzz commented 4 years ago

Hi Guys, Thanks for the help!

I have been successfully login in command line, but in the vscode-leetcode, problem remains, still not able to get problems and coding in vscode, anyone knows how can I transfer the session to vscode-leetcode?


Nvm guys, I found the solution.

In case anyone has same issue, just go vscode settings -> extensions -> leetcode, then point your file location to your local installed leetcode-cli repo, and restart your vscode, you will be logged in by default since you have session on that folder I guess.

nosensezzz commented 4 years ago

leetcode user -c is showing [ERROR] You are not login yet?. I installed most recent version of leetcode-cli. How to run this command correctly?

First use leetcode version to see if you are using the latest version. In the installation guide, note that the "From GitHub" Section gives another repo of leetcode-cli, whose master is 2.6.2. Uninstall your leetcode-cli and use npm install -g leetcode-tools/leetcode-cli to install the latest version (2.6.17).

looks like this is not working, at least for me, I have to use git command to download the repo and install locally, npm give me file not exist error.

Vigoose commented 4 years ago

Hi Guys, Thanks for the help!

I have been successfully login in command line, but in the vscode-leetcode, problem remains, still not able to get problems and coding in vscode, anyone knows how can I transfer the session to vscode-leetcode?

Nvm guys, I found the solution.

In case anyone has same issue, just go vscode settings -> extensions -> leetcode, then point your file location to your local installed leetcode-cli repo, and restart your vscode, you will be logged in by default since you have session on that folder I guess.

Hi Nosense, I also logged into command line using cookies, but I didn't find any settings you mentioned "point your file location to your local installed leetcode-cli repo"

image

Can you please specify where should I input that leetcode-cli repo?? Thanks!

jdneo commented 4 years ago

There is no VS Code setting pointing to the leetcode-cli repo.

If you want to install the leetcode-cli with cookie login support, please run npm install -g vsc-leetcode-cli

If you want to use cookie login in VS Code, just wait for this PR merged and released. The ETA would be the end of this week.

biswar100p commented 4 years ago

It appears to me that even though I'm trying to login leetcode.com, it is trying to login into leetcode-cn.com with my userid and password!! Is this what this bug is about? or, I'm seeing something different? Where are the login details specified in the code? I would like to check that out

jdneo commented 4 years ago

What information make you feeling that it is trying to login into leetcode-cn.com

nosensezzz commented 4 years ago

Hi Guys, Thanks for the help! I have been successfully login in command line, but in the vscode-leetcode, problem remains, still not able to get problems and coding in vscode, anyone knows how can I transfer the session to vscode-leetcode? Nvm guys, I found the solution. In case anyone has same issue, just go vscode settings -> extensions -> leetcode, then point your file location to your local installed leetcode-cli repo, and restart your vscode, you will be logged in by default since you have session on that folder I guess.

Hi Nosense, I also logged into command line using cookies, but I didn't find any settings you mentioned "point your file location to your local installed leetcode-cli repo"

image

Can you please specify where should I input that leetcode-cli repo?? Thanks!

Hi, Vigoose

Click those red square area should lead you to the place.

image

image

biswar100p commented 4 years ago

What information make you feeling that it is trying to login into leetcode-cn.com Update: also, the signup pop-up goes to leetcode-cn.com; if it is the same variable storing the domain name in the code, it could be the case, that it didn't change, when I switch to leetcode.com from leetcode-cn.com. But I see above a solution is proposed, I will try that now

@jdneo Hi, I might be totally wrong on this, but while tinkering around, I noticed that, the leetcode-cn API's are active, even though if I set it to leetcode.com and not leetcode-cn.com If you confirm that you are confident that is not the case, I will trust you.

jdneo commented 4 years ago

@nosensezzz Well, maybe it's working but I do not suggest to do that. This setting aims to point out the folder where you want to save your answers. Please remember to revert it back once we have released the fix.

jdneo commented 4 years ago

One solution came up in my mind:

@yihong0618 Any ideas?

yihong0618 commented 4 years ago

@jdneo I have tried the puppeteer way, but I failed. beacause the leetcode used Invisible Recaptcha which will test your score if the score not match it will cause a robot check. So I think use puppeteer-extre will be better. image

And as I metioned that this way needs headless chrome(About 100MB). But I also think your puppeteer-signin way will work if puppeteer can get the cookie and save it to vscode. I will try it maybe on Sunday.

And I search many leetcode-projects on Github, for now using webview is someway to solve this. But vscode seems not support。

jdneo commented 4 years ago

@yihong0618 I see. I'm not familiar in this area, not sure if this would gonna help.

What I'm thinking is, use puppeteer but not in headless mode, which means, the user needs to manually login in the pop-up browser window. The puppeteer is only used for popping up the browser window and getting the cookie once the user logins successfully. We won't used it to automatically fill the forms.

Will recaptcha detects this as bot action as well?

yihong0618 commented 4 years ago

@jdneo puppeteer seems not support this way. I will research it.

zhoujf620 commented 4 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, may I ask where the "vscode input field" is? I pasted cookies to ~/.lc/leetcode/user.json, but can not login in vscode-leetcode.

yihong0618 commented 4 years ago

@zhoujf620 There's no need to paste cookies to json

You can follow the steps

  1. Update vscode-leetcode to the lastest version

  2. Reload the vscode-leetcode

  3. Command "ctrl + shift +p"(if mac "command + shift + p") then type leetcode sign in by cookie

  4. Type click enter button May like this image

harsilspatel commented 4 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

this worked for me! thanks!!

wuyifat commented 4 years ago

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page

  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the "From Github" section links to an older version.

    # to remove the old version
    npm uninstall -g leetcode-cli
    # to install the up-to-date version(2.6.17+)
    npm install -g leetcode-tools/leetcode-cli

    Type leetcode version in terminal to make sure you installed version 2.6.17+.

  3. Log into leetcode.com in a browser. In Chrome, right click and select "Inspect". Switch to tab "Network", "XHR". Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from "__cfduid" and ending with "_gat=1"

  4. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

yihong0618 commented 4 years ago

# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

@wuyifat Update vscode-leetcode and reload then "ctrl + shift + p" type sign in by cookie could work for now.

nosensezzz commented 4 years ago
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

@wuyifat Update vscode-leetcode and reload then "ctrl + shift + p" type sign in by cookie could work for now.

It did works now, great catch and response.

yihong0618 commented 4 years ago

@lostindark Thank you for your idea. I have already found some way use OAuth2 for leetcode that leetcode can use third party login to avoid the Recaptcha to login. @jdneo I have a pr in leetcode-tools/leetcode-cli. Not only support third party--github login but also can avoid the Recaptcha and no need to copy the cookie in the browser.

jdneo commented 4 years ago

@yihong0618 Wow, that would be perfect!!! Thank you!

zhencode1 commented 4 years ago

@yihong0618 great thanks for that .

wuyifat commented 4 years ago
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

@wuyifat Update vscode-leetcode and reload then "ctrl + shift + p" type sign in by cookie could work for now.

Nice! Confirmed in Win10

ghost commented 4 years ago

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page
  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the "From Github" section links to an older version.
# to remove the old version
npm uninstall -g leetcode-cli
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

Type leetcode version in terminal to make sure you installed version 2.6.17+.

  1. Log into leetcode.com in a browser. In Chrome, right click and select "Inspect". Switch to tab "Network", "XHR". Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from "__cfduid" and ending with "_gat=1"
  2. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

Hmm, even though I was successfully able to sign in via cookie login none of the problems are being displayed and when I try to sign in again it says "invalid password". What exactly am I suppose to do when I'm logged in using the cookie method?

And also, Command Shift P isn't working for me.

yihong0618 commented 4 years ago

@LifeOfJona

  1. Please check your vscode-leetcode is the latest version and reload it
  2. Type" Command + Shift + p or F1" then vscode will pop up an input
  3. Then type "Sign In by Cookie" you may see somthing like below image
  4. Enter and maybe wait a little seconds (vscode-leetcode will load data) then type your account image
  5. Paste your cookie from chrome or other
  6. Type Enter and wait for below image
justin-tse commented 4 years ago

@LifeOfJona

  1. Please check your vscode-leetcode is the latest version and reload it
  2. Type" Command + Shift + p or F1" then vscode will pop up an input
  3. Then type "Sign In by Cookie" you may see somthing like below image
  4. Enter and maybe wait a little seconds (vscode-leetcode will load data) then type your account image
  5. Paste your cookie from chrome or other
  6. Type Enter and wait for below image

Thanks! It works for me. First I Sign In by Cookie and then use my username and password until I see your steps. I find I am wrong because it should use my cookie.

polar9527 commented 4 years ago

Any step-by-step instructions to solve the problem temporily ? thanks!

Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.

  1. Make sure Node.js 8+ is installed. Instructions can be found on the official page
  2. Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the "From Github" section links to an older version.
# to remove the old version
npm uninstall -g leetcode-cli
# to install the up-to-date version(2.6.17+)
npm install -g leetcode-tools/leetcode-cli

Type leetcode version in terminal to make sure you installed version 2.6.17+.

  1. Log into leetcode.com in a browser. In Chrome, right click and select "Inspect". Switch to tab "Network", "XHR". Then click any button on leetcode.com(now should be on the left split screen). Now you should be able to see the cookie as @yihong0618 showed in the pic. Copy the entire cookie string starting from "__cfduid" and ending with "_gat=1"
  2. Type leetcode user -c from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.

Hmm, even though I was successfully able to sign in via cookie login none of the problems are being displayed and when I try to sign in again it says "invalid password". What exactly am I suppose to do when I'm logged in using the cookie method?

And also, Command Shift P isn't working for me.

It works for me on MacOS . Thanks!!!!!

Aicius commented 4 years ago

@LifeOfJona

  1. Please check your vscode-leetcode is the latest version and reload it
  2. Type" Command + Shift + p or F1" then vscode will pop up an input
  3. Then type "Sign In by Cookie" you may see somthing like below image
  4. Enter and maybe wait a little seconds (vscode-leetcode will load data) then type your account image
  5. Paste your cookie from chrome or other
  6. Type Enter and wait for below image

After I input my account and password, it shows "login: login: cookie: [ERROR] invalid cookie?" . still failed.

yihong0618 commented 4 years ago

@Aicius Please make sure you are using cookie that copy from browser not your password. About how to copy: please search from this issue.

liuyanfight commented 4 years ago

Hi

I'm sure using the right cookiw in win10, but failed with error...

login: cookie: - Retrieving user favorites
[WARN] Failed to retrieve user favorites: Error: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:80
- Retrieving user profile
c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\log.js:55
      let s = args.map(x => x.toString()).join(' ');
                              ^

TypeError: Cannot read property 'toString' of undefined
    at c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\log.js:55:31
    at Array.map (<anonymous>)
    at Object.log.<computed> [as info] (c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\log.js:55:20)
    at c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\commands\user.js:81:11
    at c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\plugins\leetcode.js:528:14
    at Request._callback (c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\vsc-leetcode-cli\lib\plugins\leetcode.js:427:19)
    at self.callback (c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\request\request.js:185:22)
    at Request.emit (events.js:210:5)
    at Request.onRequestError (c:\Users\liyan\.vscode\extensions\shengchen.vscode-leetcode-0.15.8\node_modules\request\request.js:881:8)
    at ClientRequest.emit (events.js:210:5)
yihong0618 commented 4 years ago

@liuyanfight I locate your problem, maybe you are using leetcode-cn.

And I think I can change leetcode-cn in up-stream repo in the future to make the log more clear

SeanChense commented 4 years ago

@liuyanfight I locate your problem, maybe you are using leetcode-cn.

  • If you are using leetcode-cn account to login there is no need to cookie login, just use your cn account to login is fine.
  • If you are using leetcode.com account to login you have to change your endpoint from leetcode.cn to leetcode first.
  • then follow the steps to cookie login

And I think I can change leetcode-cn in up-stream repo in the future to make the log more clear

Same problem. It works.

Aicius commented 4 years ago

@Aicius Please make sure you are using cookie that copy from browser not your password. About how to copy: please search from this issue.

Hello, there are 6 different cookies? Which one to choose? Is it just past the content? IB_)N8YSGC)46_E @Y(TVSN

yihong0618 commented 4 years ago

es? Which one to choose? Is it just past

the whole content.

Aicius commented 4 years ago

es? Which one to choose? Is it just past

the whole content.

I want to ask which one of these 6 cookies to choose from...

saikrishnaklu commented 4 years ago

@Aicius you dont have to choose one just take all of them and paste it

saikrishnaklu commented 4 years ago

@liuyanfight I locate your problem, maybe you are using leetcode-cn.

  • If you are using leetcode-cn account to login there is no need to cookie login, just use your cn account to login is fine.
  • If you are using leetcode.com account to login you have to change your endpoint from leetcode.cn to leetcode first.
  • then follow the steps to cookie login

And I think I can change leetcode-cn in up-stream repo in the future to make the log more clear

Same problem. It works. I still have the problem ?? I changed the endpoint in vscode by choosing leetcode.com using pickone option. Am I missing something, could you please elaborate?

Aicius commented 4 years ago

@Aicius you dont have to choose one just take all of them and paste it

What do you mean by take all of them... I copy the content one by one and then copy & paste together but it doesn't work

superwangcheng commented 4 years ago

any workaround for new installations? I just installed the leetcode extension and seems that there is no cookie info

375C commented 4 years ago

thanks. @yihong0618 It works for me.

Bigbear325 commented 4 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


It works for me, thanks! To be more clear, the cookie is the entire String marked in Red in the pic.

leetcode

Then, In leetcode VS Code, Ctrl + Shift + P, choose, log in with cookie. Your Username, The copied Cookies. Enter!

jdneo commented 4 years ago

We now support Cookie login, third-party login (GitHub, LinkedIn)

This problem should be mitigated now.

wuqingjun commented 4 years ago

it should be mentioned,the cookie is captured in the request header when you clicks a button to send a request to leetcode.com.

DukeXar commented 4 years ago

I have tried third-party login (Github), but it failed, I guess due to 2FA enabled on Github account.

yihong0618 commented 4 years ago

2FA

@DukeXar 2FA support~ Did you have any error message?

DukeXar commented 4 years ago

@yihong0618, have just reproduced - I don't see any details in console:

[ERROR] You are not login yet?
login: pass: [ERROR] Login failed. Please make sure the credential is correct.

In the security logs of Github it was visible that 2FA was requested at the same time I was logging into the extension.

I have also checked that disabling 2FA allows to log in into the extension using Github provider.