Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
jdneo merged 9 commits intoleetcode-tools:masterfromyihong0618:master
Dec 30, 2019

Conversation

yihong0618
Copy link

…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.

Copy link

@jdneojdneo left a 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!!

@yihong0618
Copy link
Author

yihong0618 commentedDec 25, 2019
edited
Loading

@jdneo
Hi~ I fixed the code by your so kind review, thank you for your help.
And I have not solved the two-factor in vscode-leetcode maybe the sync-prompt way doesn't support I don't konw~, so thispr only support GitHub and LinkedIn way without two-factor.
By the way I found a way to add "+86" phone number with two-factor in GitHub because of this pr~
seethis, kind of interesting, share with you~
Thank you for your patience again.

@jdneo
Copy link

@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
Copy link
Author

yihong0618 commentedDec 26, 2019
edited
Loading

@jdneo
OK, the formation about the errors will send here maybe tonight.
You are right, maybe you can release the last pr and this, the vscode-leetcode side for two-factor later will be best.
And I vscode-leetcode pr has been raised~

@yihong0618
Copy link
Author

yihong0618 commentedDec 27, 2019
edited
Loading

@jdneo
I try to add two-factor in vsocde-leetcode but when prompt the two input the errors are as below

login: pass: Please enter your two-factor code:
fs.js:114
throw err;
^

Error: EOF: end of file, read
at Object.readSync (fs.js:498:3)
at prompt (c:\Users\hongyi\Documents\projects\new-vscode-leetcode\vscode-leetcode\node_modules\prompt-sync\index.js:85:17)
at Request._callback (c:\Users\hongyi\Documents\projects\new-vscode-leetcode\vscode-leetcode\node_modules\vsc-leetcode-cli\lib\plugins\leetcode.js:623:55)
at Request.self.callback (c:\Users\hongyi\Documents\projects\new-vscode-leetcode\vscode-leetcode\node_modules\request\request.js:185:22)
at Request.emit (events.js:198:13)
at Request. (c:\Users\hongyi\Documents\projects\new-vscode-leetcode\vscode-leetcode\node_modules\request\request.js:1161:10)
at Request.emit (events.js:198:13)
at IncomingMessage. (c:\Users\hongyi\Documents\projects\new-vscode-leetcode\vscode-leetcode\node_modules\request\request.js:1083:12)
at Object.onceWrapper (events.js:286:20)
at IncomingMessage.emit (events.js:203:15)

And no problem for no two-factor
image
image

I think vscode-leetcode only support GitHub login without two-factor will be good for now.
And this pr has no side effect in vscode-leetcode side.
So I think the pr can support two-factor in leetcode-cli and we can find other way to support vscode-leetcodet in the future.
Thank you~

@jdneo
Copy link

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
Copy link
Author

yihong0618 commentedDec 27, 2019
edited
Loading

@jdneo
Thank you very much.
And can you help me to solve the ci problem, because every time I failed and I don't find the infomation why.

@yihong0618
Copy link
Author

@jdneo
Just support GitHub and LinkedIn login for leetcode-cn.com

return cb(`${party} login failed or ${party} did not connect to LeetCode`);
}
let cookieData = {};
if (leetcodeUrl.includes('cn')) {

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

requestLeetcodeAndSave(_request, leetcodeUrl, user, cb, config.sys.login_methods.GitHub);
});
} else {
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb, config.sys.login_methods.GitHub);

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?

Copy link
Author

@yihong0618yihong0618Dec 30, 2019
edited
Loading

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.

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.

Copy link
Author

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: {

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

Copy link

@jdneojdneo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well done!

@jdneojdneo merged commita11e137 intoleetcode-tools:masterDec 30, 2019
@E011011101001
Copy link

Did this PR make cookie login unusable?

Inleetcode.js, functionparseCookie (Line 541) is changed andcb becomes the third parameter. However when it is called at Line 577,cb remains to be the second argument. This problem remains in the latestcommit today

When I was running this tool trying to login by cookie, I got a error saysTypeError: cb is not a function. I think this bug was imported here.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jdneojdneojdneo approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@yihong0618@jdneo@E011011101001

[8]ページ先頭

©2009-2025 Movatter.jp