-
Notifications
You must be signed in to change notification settings - Fork 677
add thrid party login -- GitHub and LinkedIn #496
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
Conversation
Hi @yihong0618,
Thank you for your contribution. I have one idea about the login experience, please let me know your thoughts on this:
We still have only one entry(command) for the login, but when users trigger the command, a drop down list pops up, having the following options:
- LeetCode Account
- LeetCode Cookie
- Third-Party: GitHub
- Third-Party: LinkedIn
By doing this, the shortcut in the explorer would be applied to all kinds of login methods. And users won't need to remember different login commands. (Imagine that we might support more 3rd-party login in the future).
BTW, the CLI with the 3rd-party login has been released, you can update the CLI to
2.6.20
in this PR.
@jdneo
You are right I also thinked of that, can I work on it this weekend and update the code?
Sure, thank you!
@jdneo vscode-leetcode 2.6.20 not found ~
My bad! It should be available right now!
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.
Thank you! Just a few comments.
README.md
Outdated
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.
Please only reserve the common login command as it was before.
src/leetCodeManager.ts
Outdated
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.
Use LeetCode cookie copied from browser to login
src/leetCodeManager.ts
Outdated
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.
Use GitHub account to login
src/leetCodeManager.ts
Outdated
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.
Use LinkedIn account to login
src/leetCodeManager.ts
Outdated
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.
No need to set the field description
to empty string if you do not want to render it. Just remove it from the Object.
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.
Is this variable inMessage
used anywhere?
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, it is for the difference of cookie login or other login message.
e.g.
promptForOpenOutputChannel(
Failed to ${inMessage}. Please open the output channel for details
src/shared.ts
Outdated
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.
loginCommand -> loginArgsMapping
2.6.21 has been published to npm
2.6.21 has been published to npm
Try again, two-factor seems can not support in our way in vscode-leetcode, because maybe the async to sync way in request is using read fs but in vscode terminal doesn't support. I will try to figure out another if i could. Thank you.
image
Can you just note users that we are not support two-factor in vscode-leetcode for now, if they want they can use cli to login first.
Thank you very much.
Thanks @yihong0618, let me also take a look first.
Thanks @yihong0618, let me also take a look first.
Thank you, that would be wonderful.
FYI
I am wrong that is zsh problem.
image
If I comment this line
if (!pwd) { childProc.kill(); return resolve(undefined); } childProc.stdin.write(`${pwd}\n`); // childProc.stdin.end();
vscode side can receive the "two-factor" message from cli side.
But I have problem with how to use the vscode.window.showInputBox
with the ondata
Sorry my laptop broke down last weekend and I have to send it to the store for repairment. I will try to resolve this PR in this week.
You can write something like this:
childProc.stdout.on("data", async (data: string | Buffer) => { data = data.toString(); leetCodeChannel.append(data); if (data.includes("two-factor")) { const twoFactor: string | undefined = await vscode.window.showInputBox({ prompt: "Enter two-factor code.", validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty", }); if (!twoFactor) { childProc.kill(); return resolve(undefined); } childProc.stdin.write(`${twoFactor}\n`); } else { const match: RegExpMatchArray | null = data.match(/(?:.*)Successfully(login|cookielogin|thirdpartylogin)as(.*)/i); if (match && match[2]) { return resolve(match[2]); } } });
But I found that there is some problems in the CLI side.
- prompt-sync is declared in the
devDependencies
, which means the module will be missing in the extension side - Why not using
prompt
butprompt-sync
?
You can write something like this:
childProc.stdout.on("data", async (data: string | Buffer) => { data = data.toString(); leetCodeChannel.append(data); if (data.includes("two-factor")) { const twoFactor: string | undefined = await vscode.window.showInputBox({ prompt: "Enter two-factor code.", validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty", }); if (!twoFactor) { childProc.kill(); return resolve(undefined); } childProc.stdin.write(`${twoFactor}\n`); } else { const match: RegExpMatchArray | null = data.match(/(?:.*)Successfully(login|cookielogin|thirdpartylogin)as(.*)/i); if (match && match[2]) { return resolve(match[2]); } } });But I found that there is some problems in the CLI side.
- prompt-sync is declared in the
devDependencies
, which means the module will be missing in the extension side- Why not using
prompt
butprompt-sync
?
Because all request with session are in callback,and prompt must in the sync way. Otherwide it will fall through。
2. I will try tonight thank you
3. I also found that~ will also fix
@jdneo
Sorry, maybe I missed somthing, it didn't work on my win10 with this way.
@yihong0618, not quite get your point. Every async can should be able to change to sync from my understanding.
You can simply change it to:
if (resp.request.uri.href !== urls.github_tf_redirect) { return requestLeetcodeAndSave(_request, leetcodeUrl, user, cb); } prompt.colors = false; prompt.message = ''; prompt.start(); prompt.get([ { name: 'code', required: true } ], function(e, result) { if (e) return log.fail(e); 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': result.code, '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); }); });
The prompt-sync
is too buggy. I'm not in favor of using that module.
By using the above code, then you can update the extension side, with following two callbacks change:
childProc.stdout.on("data", async (data: string | Buffer) => { data = data.toString(); leetCodeChannel.append(data); if (data.includes("twoFactorCode")) { const twoFactor: string | undefined = await vscode.window.showInputBox({ prompt: "Enter two-factor code.", validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty", }); if (!twoFactor) { childProc.kill(); return resolve(undefined); } childProc.stdin.write(`${twoFactor}\n`); childProc.stdin.end(); } else { const match: RegExpMatchArray | null = data.match(/(?:.*)Successfully.*loginas(.*)/i); if (match && match[1]) { childProc.stdin.end(); return resolve(match[1]); } } });
&
childProc.on("close", (code: number) => { if (code !== 0) { reject(new Error("Failed to login.`")); } });
@jdneo
You are right. Because I put the GitHub login without two-factor in the end of the code block, so it would fall through using prompt. And I think you are right. Really learned a lot from your project and the JS(TS), thank you. I will fix these tonight.
@yihong0618 No worry, I should thank you for all of the contributions you have made.
Will take a look at the PR recently.
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.
:shipit:
add thrid party login -- GitHub and LinkedIn.