Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

add third party github login for future updates in vscode-leetcode #34

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

Merged
merged 5 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix typo
  • Loading branch information
yihong0618 committed Dec 18, 2019
commit 3663a98d1a63d68de3725f36d55196ecf4933ec2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Great thanks to leetcode.com, a really awesome website!
Read help first $ leetcode help
Login with your leetcode account $ leetcode user -l
Login with third party account--GitHub $ leetcode user -g
Login with third party account--Linkedin $ leetcode user -i
Login with third party account--LinkedIn $ leetcode user -i
Cookie login with cookie $ leetcode user -c
Browse all questions $ leetcode list
Choose one question $ leetcode show 1 -g -l cpp
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const cmd = {
alias: 'linkedin',
type: 'boolean',
default: false,
describe: 'linkinedLogin'
describe: 'linkedinLogin'
})
.option('L', {
alias: 'logout',
Expand All @@ -49,7 +49,7 @@ const cmd = {
.example(chalk.yellow('leetcode user -l'), 'User login')
.example(chalk.yellow('leetcode user -c'), 'User Cookie login')
.example(chalk.yellow('leetcode user -g'), 'User GitHub login')
.example(chalk.yellow('leetcode user -i'), 'User Linkedin login')
.example(chalk.yellow('leetcode user -i'), 'User LinkedIn login')
.example(chalk.yellow('leetcode user -L'), 'User logout');
}
};
Expand Down Expand Up @@ -87,7 +87,7 @@ cmd.handler = function(argv) {
[
['g', core.githubLogin],
['github', core.githubLogin],
['i', core.linkinedLogin],
['i', core.linkedinLogin],
['linkedin', core.linkedinLogin],
]
);
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const DEFAULT_CONFIG = {
base: 'https://leetcode.com',
graphql: 'https://leetcode.com/graphql',
login: 'https://leetcode.com/accounts/login/',
// third part login base urls. TODO facebook linkin google
// third part login base urls. TODO facebook google
github_login: 'https://leetcode.com/accounts/github/login/?next=%2F',
facebook_login: 'https://leetcode.com/accounts/facebook/login/?next=%2F',
linkined_login: 'https://leetcode.com/accounts/linkedin_oauth2/login/?next=%2F',
linkedin_login: 'https://leetcode.com/accounts/linkedin_oauth2/login/?next=%2F',
problems: 'https://leetcode.com/api/problems/$category/',
problem: 'https://leetcode.com/problems/$slug/description/',
test: 'https://leetcode.com/problems/$slug/interpret_solution/',
Expand Down
14 changes: 7 additions & 7 deletions lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ plugin.githubLogin = function(user, cb) {
_request.get({url: leetcodeUrl}, function(e, resp, body) {
const redirectUri = resp.request.uri.href;
if (redirectUri !== 'https://leetcode.com/') {
return cb('GitHub login failed or GitHub did not link to leetcode');
return cb('GitHub login failed or GitHub did not link to LeetCode');
}
const cookieData = parseCookie(resp.request.headers.cookie, cb);
saveAndGetUser(user, cb, cookieData);
Expand All @@ -606,8 +606,8 @@ plugin.githubLogin = function(user, cb) {
});
};

plugin.linkinedLogin = function(user, cb) {
const leetcodeUrl = config.sys.urls.linkined_login;
plugin.linkedinLogin = function(user, cb) {
const leetcodeUrl = config.sys.urls.linkedin_login;
const _request = request.defaults({
jar: true,
headers: {
Expand All @@ -616,11 +616,11 @@ plugin.linkinedLogin = function(user, cb) {
});
_request('https://www.linkedin.com', function(e, resp, body) {
if ( resp.statusCode !== 200) {
return cb('Get linkedin session failed');
return cb('Get linkedIn session failed');
}
const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /);
if (authenticityToken === null) {
return cb('Get Linkedin token failed');
return cb('Get LinkedIn token failed');
}
const options = {
url: 'https://www.linkedin.com/uas/login-submit',
Expand All @@ -638,12 +638,12 @@ plugin.linkinedLogin = function(user, cb) {
};
_request(options, function(e, resp, body) {
if (resp.statusCode !== 200) {
return cb('Linkedin login failed');
return cb('LinkedIn login failed');
}
_request.get({url: leetcodeUrl}, function(e, resp, body) {
const redirectUri = resp.request.uri.href;
if (redirectUri !== 'https://leetcode.com/') {
return cb('Linkedin login failed or Linkedin did not link to leetcode');
return cb('LinkedIn login failed or LinkedIn did not link to LeetCode');
}
const cookieData = parseCookie(resp.request.headers.cookie, cb);
saveAndGetUser(user, cb, cookieData);
Expand Down