-
Notifications
You must be signed in to change notification settings - Fork 51
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solve GitHub login two-factor auth problem and add new node package p… #35
Conversation
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!!
@jdneo |
@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? |
@jdneo |
@jdneo
And no problem for no two-factor I think vscode-leetcode only support GitHub login without two-factor will be good for now. |
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. |
@jdneo |
@jdneo |
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
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 of requestLeetcodeAndSave
in line 648 and line 651 merged into one call -- move it out of the if-else block?
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) {
return requestLeetcodeAndSave(_request, leetcodeUrl, user, cb, config.sys.login_methods.GitHub);
}
cb('Your GitHub are using two-factor authentication');
// read two-factor code must be sync.
const twoFactorcode = require('prompt-sync')()('Please enter your two-factor code: ');
const authenticityTokenTwoFactor = body.match(/name="authenticity_token" value="(.*?)"/);
if (authenticityTokenTwoFactor === null) {
return cb('Get GitHub two-factor token failed');
}
const optionsTwoFactor = {
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) {
return cb('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.
…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
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!
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.