From 4a27102bd629f7f3a93cb250752d26efc24da683 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Thu, 28 May 2020 14:54:16 +0800 Subject: [PATCH 1/5] fix: can not download plugins bug --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index ed390f04..f78d5d12 100644 --- a/lib/config.js +++ b/lib/config.js @@ -60,7 +60,7 @@ const DEFAULT_CONFIG = { verify: 'https://leetcode.com/submissions/detail/$id/check/', favorites: 'https://leetcode.com/list/api/questions', favorite_delete: 'https://leetcode.com/list/api/questions/$hash/$id', - plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli-plugins/master/plugins/$name.js' + plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli/master/lib/plugins/$name.js' }, }, From 982e743952ac565a9fdb2075da764180afd5ab49 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Thu, 28 May 2020 15:33:10 +0800 Subject: [PATCH 2/5] fix: LinkedIn change login way bug --- lib/config.js | 4 ++-- lib/plugins/leetcode.js | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/config.js b/lib/config.js index f78d5d12..b390ba7e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -47,8 +47,8 @@ const DEFAULT_CONFIG = { github_login_request: 'https://github.com/login', github_session_request: 'https://github.com/session', github_tf_session_request: 'https://github.com/sessions/two-factor', - linkedin_login_request: 'https://www.linkedin.com', - linkedin_session_request: 'https://www.linkedin.com/uas/login-submit', + linkedin_login_request: 'https://www.linkedin.com/login', + linkedin_session_request: 'https://www.linkedin.com/checkpoint/lg/login-submit', // questions urls problems: 'https://leetcode.com/api/problems/$category/', problem: 'https://leetcode.com/problems/$slug/description/', diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index cf2231db..48cb789e 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -563,6 +563,7 @@ function parseCookie(cookie, body, cb) { function requestLeetcodeAndSave(request, leetcodeUrl, user, cb) { request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; + console.log(redirectUri); if (redirectUri !== config.sys.urls.leetcode_redirect) { return cb('Login failed. Please make sure the credential is correct.'); } @@ -664,8 +665,12 @@ plugin.linkedinLogin = function(user, cb) { if ( resp.statusCode !== 200) { return cb('Get LinkedIn session failed'); } - const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /); - if (authenticityToken === null) { + const csrfToken = body.match(/input type="hidden" name="csrfToken" value="(.*?)"/); + const loginCsrfToken = body.match(/input type="hidden" name="loginCsrfParam" value="(.*?)"/); + const sIdString = body.match(/input type="hidden" name="sIdString" value="(.*?)"/); + const pageInstance = body.match(/input type="hidden" name="pageInstance" value="(.*?)"/); + console.log(csrfToken[1], loginCsrfToken[1], sIdString[1], pageInstance[1]); + if (loginCsrfToken === null) { return cb('Get LinkedIn token failed'); } const options = { @@ -676,10 +681,22 @@ plugin.linkedinLogin = function(user, cb) { }, followAllRedirects: true, form: { - 'session_key': user.login, - 'session_password': user.pass, - 'loginCsrfParam': authenticityToken[1], - 'trk': 'guest_homepage-basic_sign-in-submit' + 'csrfToken': csrfToken[1], + 'session_key': user.login, + 'ac': 2, + 'sIdString': sIdString[1], + 'parentPageKey': 'd_checkpoint_lg_consumerLogin', + 'pageInstance': pageInstance[1], + 'trk': 'public_profile_nav-header-signin', + 'authUUID': '', + 'session_redirect': 'https://www.linkedin.com/feed/', + 'loginCsrfParam': loginCsrfToken[1], + 'fp_data': 'default', + '_d': 'd', + 'showGoogleOneTapLogin': true, + 'controlId': 'd_checkpoint_lg_consumerLogin-login_submit_button', + 'session_password': user.pass, + 'loginFlow': 'REMEMBER_ME_OPTIN' }, }; _request(options, function(e, resp, body) { From 06f6569bf43d9af93dd898af0a7b8efe46fc1de0 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Thu, 28 May 2020 15:55:08 +0800 Subject: [PATCH 3/5] drop: useless console.log, fix: error message --- lib/plugins/leetcode.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 48cb789e..dfeb4373 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -669,9 +669,8 @@ plugin.linkedinLogin = function(user, cb) { const loginCsrfToken = body.match(/input type="hidden" name="loginCsrfParam" value="(.*?)"/); const sIdString = body.match(/input type="hidden" name="sIdString" value="(.*?)"/); const pageInstance = body.match(/input type="hidden" name="pageInstance" value="(.*?)"/); - console.log(csrfToken[1], loginCsrfToken[1], sIdString[1], pageInstance[1]); - if (loginCsrfToken === null) { - return cb('Get LinkedIn token failed'); + if (!(csrfToken && loginCsrfToken && sIdString && pageInstance)) { + return cb('Get LinkedIn payload failed'); } const options = { url: urls.linkedin_session_request, From eb8da4831f1f89803a387f6ad99cda3ebc0f3136 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Mon, 1 Jun 2020 22:01:32 +0800 Subject: [PATCH 4/5] fix: GihHub login for leetcode --- lib/plugins/leetcode.js | 44 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index dfeb4373..d7553e20 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -540,22 +540,16 @@ plugin.login = function(user, cb) { }; function parseCookie(cookie, body, cb) { - const isCN = config.app === 'leetcode.cn'; const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/; - let csrfPattern; - // leetcode-cn.com Cookie is not the same as leetcode.com in third parties - if (isCN) { - csrfPattern = /name="csrfmiddlewaretoken" value="(.*?)"/; - } else { - csrfPattern = /csrftoken=(.+?)(;|$)/; - } + const csrfPattern = /csrftoken=(.+?)(;|$)/; const reSessionResult = SessionPattern.exec(cookie); - const reCsrfResult = csrfPattern.exec(isCN? body: cookie); + const reCsrfResult = csrfPattern.exec(cookie); if (reSessionResult === null || reCsrfResult === null) { return cb('invalid cookie?'); } return { - sessionId: reSessionResult[1], + // sessionId: SessionResult[1], + sessionId: cookie, sessionCSRF: reCsrfResult[1], }; } @@ -563,7 +557,6 @@ function parseCookie(cookie, body, cb) { function requestLeetcodeAndSave(request, leetcodeUrl, user, cb) { request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; - console.log(redirectUri); if (redirectUri !== config.sys.urls.leetcode_redirect) { return cb('Login failed. Please make sure the credential is correct.'); } @@ -589,9 +582,18 @@ plugin.githubLogin = function(user, cb) { const _request = request.defaults({jar: true}); _request(urls.github_login_request, function(e, resp, body) { const authenticityToken = body.match(/name="authenticity_token" value="(.*?)"/); - if (authenticityToken === null) { - return cb('Get GitHub token failed'); + let gaId = body.match(/name="ga_id" value="(.*?)"/); + if (!gaId) { + gaId = ''; + } + let requiredField = body.match(/name="required_field_(.*?)"/); + const timestamp = body.match(/name="timestamp" value="(.*?)"/); + const timestampSecret = body.match(/name="timestamp_secret" value="(.*?)"/); + + if (!(authenticityToken && timestamp && timestampSecret && requiredField)) { + return cb('Get GitHub payload failed'); } + requiredField = 'required_field_' + requiredField[1]; const options = { url: urls.github_session_request, method: 'POST', @@ -600,11 +602,17 @@ plugin.githubLogin = function(user, cb) { }, followAllRedirects: true, form: { - 'login': user.login, - 'password': user.pass, - 'authenticity_token': authenticityToken[1], - 'utf8': encodeURIComponent('✓'), - 'commit': encodeURIComponent('Sign in') + 'login': user.login, + 'password': user.pass, + 'authenticity_token': authenticityToken[1], + 'commit': encodeURIComponent('Sign in'), + 'ga_id': gaId, + 'webauthn-support': 'supported', + 'webauthn-iuvpaa-support': 'unsupported', + 'return_to': '', + 'requiredField': '', + 'timestamp': timestamp[1], + 'timestamp_secret': timestampSecret[1], }, }; _request(options, function(e, resp, body) { From c3f52435a58d88dc7cd66907be61abf09720a23e Mon Sep 17 00:00:00 2001 From: yihong Date: Mon, 1 Jun 2020 23:16:10 +0800 Subject: [PATCH 5/5] bug: fix --- lib/plugins/leetcode.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index d7553e20..8855f689 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -548,8 +548,7 @@ function parseCookie(cookie, body, cb) { return cb('invalid cookie?'); } return { - // sessionId: SessionResult[1], - sessionId: cookie, + sessionId: reSessionResult[1], sessionCSRF: reCsrfResult[1], }; }