vscode-leetcode: Failed to log in with a leetcode.com account
🐛 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
- os: Windows 10 Family Edition x64 (#18362)
- extension settings: default
- nodejs version: 12.4.0
- vscode version: 1.40.1
- extension version: 0.15.7
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 55
- Comments: 261 (47 by maintainers)
Spent an hour and figured it out. Here are the step by step instructions by people newbie like me.
Make sure Node.js 8+ is installed. Instructions can be found on the official page
Install leetcode-cli from OS terminal or the terminal within vscode. Installation guide. Note the “From Github” section links to an older version.
Type
leetcode version
in terminal to make sure you installed version 2.6.17+.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”
Type
leetcode user -c
from terminal within vscode. Follow the prompt and type in your username and cookie you copied above.Just to confirm what worked for me, thanks to whoever posted the solution.
It works for me, thanks! To be more clear, the cookie is the entire String marked in Red in the pic.
Then, In leetcode VS Code, Ctrl + Shift + P, choose, log in with cookie. Your Username, The copied Cookies. Enter!
if anyone encounter this issue, you can try to login use cookie
first select the last option [login via cookie]
login in your leetcode account in any browser
open the developer tool of your browser, select [network] tab
click on any request that has header, copy the cookie in the header
back to vscode, input your username,press [enter], then paste the cookie from step 4, then submit
and you will login in your account successfully. 😃
@jdneo @lostindark
@jdneo
The demo will be like below (user can only copy the cookie and vscode-cli will parser it ):
This cookie but need to add some guide。
My hero 😍
Thank you so much. It is working perfectly. 😃
If you use chromium-based browsers there’s this extension I made that you can use to copy cookies: https://chromewebstore.google.com/detail/vsleet/ihgifhobfmjhcelknpbjhpabkcghjmfh?hl=en
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.
But the leetcode-cn’s payload is as usual.
And the leetcode-cli’s login payload is like below.
I think may use another way to login and get the session or solve the recaptcha.
@jdneo @queensferryme
This worked for me…
node --version
of 12.0.0npm install -g n
sudo n 12.0.0
npm install -g leetcode-cli
do this in order to configure the creds for your leetcode-cli session
Check that your session is working via
leetcode session
, which should look like:=================================================
The below cookie method no longer works but is kept for posterity
3) Get Cookie ValueOpen Chrome (must be Chrome, not Firefox) and go to https://leetcode.com/problemset/all/ (login if not already)Navigate to View > Web Developer > Network, then filter for XHR request ofall/
and copy thecookie
value:The cookie should start with__cfduid=
and end with_gat=1
4) Load Cookie Valueleetcode user -c
<enter your email address>
<paste the cookie value>
You should see output ofSuccessfully cookie login as <username>
On macOS Monterey using Safari ⬇️
In VScode 😎
1、找到leetcode插件位置,打开leetcode.js,找到这个位置 2、在网页上登录https://leetcode-cn.com/,登录成功之后F12, copy LEETCODE_SESSION和csrftoken,注意对应 3、修改leetcode.js上面的代码
然后保存,之后在vscode登录leetcode, 选择直接登录,账号密码随便输入就行
same question. It worked yesterday, but not today
@saksham1211 I have a leetcode.com account that just uses my email (not 3rd party) and the cookie method works for me currently. While the cookie looks quite different, it still works.
You have to copy the entire cookie string.
It turns out that the cookies that we get from the website has changed its format:
And now I have
@Cering There are two steps to get the cookie
I found a workaround works for me.
I’ve noticed vscode-leetcode now utilizes vsc-leetcode-cli which only parses and uses ‘LEETCODE_SESSION’ and ‘csrftoken’ from the input cookie string when we login with the ‘Leetcode Cookie’ option.
So i just input a minimum custom cookie string to login like: “LEETCODE_SESSION=xxxxxxxxx;csrftoken=xxxxx;”,and we can find the values of ‘LEETCODE_SESSION’ and ‘csrftoken’ in the storage cookies under the ‘Application’ tab of the browser dev tools when we use our browser to vist leetcode.com.
Try the realname in the ‘Response’ for username of login and whole cookie, it work for me.
Oh, As I directly copy all of the content in “all/” tag, it works.
For ppl tried all the above suggestions but still failed:
I tried to get the cookies (graphql, non graphql starting with “_ga” and other solutions) from Firefox and kept getting either “cb” error or “x.toString()” error, and none of the above resolves my issue. Until I switched to Chrome to get the cookie and succeeded with graphql request cookie value. (something starts with “gr_user_id=”)
switch to leetcode-cn.com and you can use it
i want use github account number to sign in but in vain, lord help me , i want to study
Can not login with cookies.
Refresh the page. Go to the networks tab in developer options. Select Fetch/XHR. Under the names sections, select any graphql req/res. Go to the request headers section. Locate the cookie key there. Select only this part of the cookie value -> csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; Open terminal, type leetcode user -c Enter username and this cookie value.
thank you so much, got it working now 😃
The prompt doesn’t clarify what format do we need to input. There’s no field starting with “__cfduid” or with “_gat=1” in the cookie these days.
Wasting 10 minutes browsing the post and finally I found the answer: cookies with the format of semicolon separated pairs. (You need all the cookies, not a single field)
Fuck leetcode-cli, you don’t want it. Install EditThisCookie extension and change the export format and export the cookie. That’s it.
xhr
I clicked theall problems
We now support Cookie login, third-party login (GitHub, LinkedIn)
This problem should be mitigated now.
Yeah boy
你好,邮件收到了,会尽快回复。
This works, thanks.
@LifeOfJona
@zhoujf620 There’s no need to paste cookies to json
You can follow the steps
Update vscode-leetcode to the lastest version
Reload the vscode-leetcode
Command “ctrl + shift +p”(if mac “command + shift + p”) then type leetcode sign in by cookie
Type click enter button May like this
same
https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478#issuecomment-1786257954
It works, thanks! I still don’t understand why it gets the different cookies than I get from browser developer mode. But the cookies it gets works fine and I logged in in VS-code smoothly.
《csrftoken=“xyz”; LEETCODE_SESSION=“xyz”;》 Can solve this problem
Hey, I am not able to log in using any of the method provided here. I did all what the people on this thread suggested but failed to log into my account. 😦
Got this error. Anyone found any solutions?
today(2021/6/4) this solution is not work.
Still facing this error. With cookies it fails with
TypeError: Cannot read property 'isCurrentUserPremium' of null
Doesnt login with github because of TFA and linkedin too.@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
was having this problem but this solution worked
just copy and paste csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; somewhere else then go grab the two cookie values and replace xyz with them. after that copy the entire thing and use it as cookie login
Thanks this worked for me via a extra step so anyone can try this, follow the above things and after leetcode user -c command, enter then write like username csrftoken=“xyz”; LEETCODE_SESSION=“xyz”; After this it asked me for cookie again then write the same thing again and it will work.
I don’t want to, but I can’t log in by changing to cn…
There is no change in the extension sleeve code of the vscode, and is there no progress on the issue now? 😞
My LeetCode uninstalled once and I couldn’t log in ,my version is 0.17.0 node js s version is 15.50, vscode 1.52.1 thanks
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.
After adding some logs, it seems that the login requests are blocked by Cloudflare’s JS Challenge. Have tried changing IPs and adding headers like User-Agent, but still not working. Perhaps it’s related to some Cloudflare specified cookies to check if the request is from a browser or a script, not sure what to do next.
same question, it was working fine in yesterday, but when I try to use this plugin today, it just cannot login.
+1
I was able to use the Cookie way to log in.
I don’t know why it’s not working last time. But this morning I tried it with my email and the cookie with the format of:
csrftoken=“xyz”;LEETCODE_SESSION=“xyz”;
Hope this will help.
你好,邮件收到了,会尽快回复。
For people facing same issue as the original post: May be useful to somebody to note that after a few attempts the only way I was able to get it working with the cookie login was by using the cookie value specifically in the header for home/.
Thanks for your help. However when I type in “leetcode user -c” there is an error and it is not working when try to type my username and cookie, check the screenshot.
I also tried to use the username and cookie directly(the 4th option in below screenshot), so lucky either.
Confirmed: cookie login works for US endpoint. The key point is to copy the whole cookie, not just the string after the semicolon.
@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
It did works now, great catch and response.
@wuyifat Update vscode-leetcode and reload then “ctrl + shift + p” type sign in by cookie could work for now.
Hi @ericjjj,
Would you mind to explain more about your solution?
Thanks.
Is there a way to paste the cookies from browser into the extension? So it doesn’t have to automate the login process. @jdneo
I tried this, and it worked.
https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/927#issuecomment-1986832815
你好,邮件收到了,会尽快回复。
it’s still not working , i tried it with my email and the cookie with the format of: csrftoken=“xyz”;LEETCODE_SESSION=“xyz”;
Thanks, this work for me.
Hi @yihong0618, I was trying to follow this solution to login by using LEETCODE_SESSION value from browser, but it failed with following error message:
Could you provide any help?
can you please reply in details?
just copying the whole cookie thing would work, not the text “csrftoken***********Z0”. or you could try both. one of them worked for me though
using leetcode.com not leetcode-cn.com cant solve this problem !
Found that it might be browser dependent. Copying a cookie from a Chrome network tab works, copying from a Firefox console doesn’t.
Thats true. The cookie format has been changed and there’s no “_sat=1” string towards the end of the cookie anymore.
Gives the same error as above:
@yihong0618 Thank you, as always 👍
@yihong0618 Thanks, it works now.
I think so.
@DukeXar when you use your 2FA account, did you wait a few seconds, and there will be a pop up like below
it should be mentioned,the cookie is captured in the request header when you clicks a button to send a request to leetcode.com.
After I input my account and password, it shows “login: login: cookie: [ERROR] invalid cookie?” . still failed.
It works for me on MacOS . Thanks!!!
@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.
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?
@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).
This problem is a little bit tricky. Recaptcha is hard to deal without a browser. I can think of 2 ways to fix this:
None of these are simple, maybe we should talk to leetcode and see if there are any support way of login for plugins?
+1