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

Commit 5a23270

Browse files
Fix: LinkedIn login problem. (leetcode-tools#43)
* fix: can not download plugins bug * fix: LinkedIn change login way bug * drop: useless console.log, fix: error message * fix: GihHub login for leetcode * bug: fix
1 parent 3818bc5 commit 5a23270

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

‎lib/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const DEFAULT_CONFIG = {
4747
github_login_request: 'https://github.com/login',
4848
github_session_request: 'https://github.com/session',
4949
github_tf_session_request: 'https://github.com/sessions/two-factor',
50-
linkedin_login_request: 'https://www.linkedin.com',
51-
linkedin_session_request: 'https://www.linkedin.com/uas/login-submit',
50+
linkedin_login_request: 'https://www.linkedin.com/login',
51+
linkedin_session_request: 'https://www.linkedin.com/checkpoint/lg/login-submit',
5252
// questions urls
5353
problems: 'https://leetcode.com/api/problems/$category/',
5454
problem: 'https://leetcode.com/problems/$slug/description/',
@@ -60,7 +60,7 @@ const DEFAULT_CONFIG = {
6060
verify: 'https://leetcode.com/submissions/detail/$id/check/',
6161
favorites: 'https://leetcode.com/list/api/questions',
6262
favorite_delete: 'https://leetcode.com/list/api/questions/$hash/$id',
63-
plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli-plugins/master/plugins/$name.js'
63+
plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli/master/lib/plugins/$name.js'
6464
},
6565
},
6666

‎lib/plugins/leetcode.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,10 @@ plugin.login = function(user, cb) {
540540
};
541541

542542
function parseCookie(cookie, body, cb) {
543-
const isCN = config.app === 'leetcode.cn';
544543
const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/;
545-
let csrfPattern;
546-
// leetcode-cn.com Cookie is not the same as leetcode.com in third parties
547-
if (isCN) {
548-
csrfPattern = /name="csrfmiddlewaretoken"value="(.*?)"/;
549-
} else {
550-
csrfPattern = /csrftoken=(.+?)(;|$)/;
551-
}
544+
const csrfPattern = /csrftoken=(.+?)(;|$)/;
552545
const reSessionResult = SessionPattern.exec(cookie);
553-
const reCsrfResult = csrfPattern.exec(isCN? body: cookie);
546+
const reCsrfResult = csrfPattern.exec(cookie);
554547
if (reSessionResult === null || reCsrfResult === null) {
555548
return cb('invalid cookie?');
556549
}
@@ -588,9 +581,18 @@ plugin.githubLogin = function(user, cb) {
588581
const _request = request.defaults({jar: true});
589582
_request(urls.github_login_request, function(e, resp, body) {
590583
const authenticityToken = body.match(/name="authenticity_token"value="(.*?)"/);
591-
if (authenticityToken === null) {
592-
return cb('Get GitHub token failed');
584+
let gaId = body.match(/name="ga_id"value="(.*?)"/);
585+
if (!gaId) {
586+
gaId = '';
587+
}
588+
let requiredField = body.match(/name="required_field_(.*?)"/);
589+
const timestamp = body.match(/name="timestamp"value="(.*?)"/);
590+
const timestampSecret = body.match(/name="timestamp_secret"value="(.*?)"/);
591+
592+
if (!(authenticityToken && timestamp && timestampSecret && requiredField)) {
593+
return cb('Get GitHub payload failed');
593594
}
595+
requiredField = 'required_field_' + requiredField[1];
594596
const options = {
595597
url: urls.github_session_request,
596598
method: 'POST',
@@ -599,11 +601,17 @@ plugin.githubLogin = function(user, cb) {
599601
},
600602
followAllRedirects: true,
601603
form: {
602-
'login': user.login,
603-
'password': user.pass,
604-
'authenticity_token': authenticityToken[1],
605-
'utf8': encodeURIComponent('✓'),
606-
'commit': encodeURIComponent('Sign in')
604+
'login': user.login,
605+
'password': user.pass,
606+
'authenticity_token': authenticityToken[1],
607+
'commit': encodeURIComponent('Sign in'),
608+
'ga_id': gaId,
609+
'webauthn-support': 'supported',
610+
'webauthn-iuvpaa-support': 'unsupported',
611+
'return_to': '',
612+
'requiredField': '',
613+
'timestamp': timestamp[1],
614+
'timestamp_secret': timestampSecret[1],
607615
},
608616
};
609617
_request(options, function(e, resp, body) {
@@ -664,9 +672,12 @@ plugin.linkedinLogin = function(user, cb) {
664672
if ( resp.statusCode !== 200) {
665673
return cb('Get LinkedIn session failed');
666674
}
667-
const authenticityToken = body.match(/inputname="loginCsrfParam"value="(.*)"/);
668-
if (authenticityToken === null) {
669-
return cb('Get LinkedIn token failed');
675+
const csrfToken = body.match(/inputtype="hidden"name="csrfToken"value="(.*?)"/);
676+
const loginCsrfToken = body.match(/inputtype="hidden"name="loginCsrfParam"value="(.*?)"/);
677+
const sIdString = body.match(/inputtype="hidden"name="sIdString"value="(.*?)"/);
678+
const pageInstance = body.match(/inputtype="hidden"name="pageInstance"value="(.*?)"/);
679+
if (!(csrfToken && loginCsrfToken && sIdString && pageInstance)) {
680+
return cb('Get LinkedIn payload failed');
670681
}
671682
const options = {
672683
url: urls.linkedin_session_request,
@@ -676,10 +687,22 @@ plugin.linkedinLogin = function(user, cb) {
676687
},
677688
followAllRedirects: true,
678689
form: {
679-
'session_key': user.login,
680-
'session_password': user.pass,
681-
'loginCsrfParam': authenticityToken[1],
682-
'trk': 'guest_homepage-basic_sign-in-submit'
690+
'csrfToken': csrfToken[1],
691+
'session_key': user.login,
692+
'ac': 2,
693+
'sIdString': sIdString[1],
694+
'parentPageKey': 'd_checkpoint_lg_consumerLogin',
695+
'pageInstance': pageInstance[1],
696+
'trk': 'public_profile_nav-header-signin',
697+
'authUUID': '',
698+
'session_redirect': 'https://www.linkedin.com/feed/',
699+
'loginCsrfParam': loginCsrfToken[1],
700+
'fp_data': 'default',
701+
'_d': 'd',
702+
'showGoogleOneTapLogin': true,
703+
'controlId': 'd_checkpoint_lg_consumerLogin-login_submit_button',
704+
'session_password': user.pass,
705+
'loginFlow': 'REMEMBER_ME_OPTIN'
683706
},
684707
};
685708
_request(options, function(e, resp, body) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /