diff --git a/lib/config.js b/lib/config.js index ed390f04..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/', @@ -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' }, }, diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index cf2231db..8855f689 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -540,17 +540,10 @@ 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?'); } @@ -588,9 +581,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', @@ -599,11 +601,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) { @@ -664,9 +672,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) { - return cb('Get LinkedIn token failed'); + 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="(.*?)"/); + if (!(csrfToken && loginCsrfToken && sIdString && pageInstance)) { + return cb('Get LinkedIn payload failed'); } const options = { url: urls.linkedin_session_request, @@ -676,10 +687,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) {