- Notifications
You must be signed in to change notification settings - Fork51
solve GitHub login two-factor auth problem and add new node package p…#35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
jdneo left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I just tried with my GitHub account and it works!!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
yihong0618 commentedDec 25, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jdneo |
jdneo commentedDec 26, 2019
@yihong0618 could you please share more information about the errors you observed from the vs code extension side? Since the third-party login can unblock a lot of users, how about we release a new CLI without the two-factor auth support at first. Then we revisit this issue after that? |
yihong0618 commentedDec 26, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jdneo |
yihong0618 commentedDec 27, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jdneo
And no problem for no two-factor I think vscode-leetcode only support GitHub login without two-factor will be good for now. |
jdneo commentedDec 27, 2019
I see. I'll release the CLI first to unblock the vscode-leetcode's PR. Just leave this PR here for now until we release the VS Code LeetCode. |
yihong0618 commentedDec 27, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jdneo |
@jdneo |
Uh oh!
There was an error while loading.Please reload this page.
lib/plugins/leetcode.js Outdated
return cb(`${party} login failed or ${party} did not connect to LeetCode`); | ||
} | ||
let cookieData = {}; | ||
if (leetcodeUrl.includes('cn')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
cn
->leetcode-cn.com
to avoid mismatch
Uh oh!
There was an error while loading.Please reload this page.
lib/plugins/leetcode.js Outdated
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb, config.sys.login_methods.GitHub); | ||
}); | ||
} else { | ||
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb, config.sys.login_methods.GitHub); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can the calling ofrequestLeetcodeAndSave
in line 648 and line 651 merged into one call -- move it out of the if-else block?
yihong0618Dec 30, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sorry, these two are with different session(_request), the first one is two-factor, the second one is normal. Both need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I see. How about
if(resp.request.uri.href!==urls.github_tf_redirect){returnrequestLeetcodeAndSave(_request,leetcodeUrl,user,cb,config.sys.login_methods.GitHub);}cb('Your GitHub are using two-factor authentication');// read two-factor code must be sync.consttwoFactorcode=require('prompt-sync')()('Please enter your two-factor code: ');constauthenticityTokenTwoFactor=body.match(/name="authenticity_token"value="(.*?)"/);if(authenticityTokenTwoFactor===null){returncb('Get GitHub two-factor token failed');}constoptionsTwoFactor={url:urls.github_tf_session_request,method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded',},followAllRedirects:true,form:{'otp':twoFactorcode,'authenticity_token':authenticityTokenTwoFactor[1],'utf8':encodeURIComponent('✓'),},};_request(optionsTwoFactor,function(e,resp,body){if(resp.request.uri.href===urls.github_tf_session_request){returncb('Invalid two-factor code please check');}requestLeetcodeAndSave(_request,leetcodeUrl,user,cb,config.sys.login_methods.GitHub);});
which can save some indentions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes! Very clean code. Thank you.
Uh oh!
There was an error while loading.Please reload this page.
…e if cn test) to make it more clear, also fixed a tiny bug before
lib/config.js Outdated
plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli-plugins/master/plugins/$name.js' | ||
}, | ||
// login methods enum | ||
login_methods: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This field can also be removed
jdneo left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Well done!
E011011101001 commentedMar 16, 2022
Did this PR make cookie login unusable? In When I was running this tool trying to login by cookie, I got a error says |
…rompt-sync
Solve two-factor auth problem and format some code.
Please help me check if this way can use in vscode-leetcode or not, because I did not find a way, thank you very much.