@@ -540,17 +540,10 @@ plugin.login = function(user, cb) {
540540} ;
541541
542542function parseCookie ( cookie , body , cb ) {
543- const isCN = config . app === 'leetcode.cn' ;
544543 const SessionPattern = / L E E T C O D E _ S E S S I O N = ( .+ ?) ( ; | $ ) / ;
545- let csrfPattern ;
546- // leetcode-cn.com Cookie is not the same as leetcode.com in third parties
547- if ( isCN ) {
548- csrfPattern = / n a m e = " c s r f m i d d l e w a r e t o k e n " v a l u e = " ( .* ?) " / ;
549- } else {
550- csrfPattern = / c s r f t o k e n = ( .+ ?) ( ; | $ ) / ;
551- }
544+ const csrfPattern = / c s r f t o k e n = ( .+ ?) ( ; | $ ) / ;
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 ( / n a m e = " a u t h e n t i c i t y _ t o k e n " v a l u e = " ( .* ?) " / ) ;
591- if ( authenticityToken === null ) {
592- return cb ( 'Get GitHub token failed' ) ;
584+ let gaId = body . match ( / n a m e = " g a _ i d " v a l u e = " ( .* ?) " / ) ;
585+ if ( ! gaId ) {
586+ gaId = '' ;
587+ }
588+ let requiredField = body . match ( / n a m e = " r e q u i r e d _ f i e l d _ ( .* ?) " / ) ;
589+ const timestamp = body . match ( / n a m e = " t i m e s t a m p " v a l u e = " ( .* ?) " / ) ;
590+ const timestampSecret = body . match ( / n a m e = " t i m e s t a m p _ s e c r e t " v a l u e = " ( .* ?) " / ) ;
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 ( / i n p u t n a m e = " l o g i n C s r f P a r a m " v a l u e = " ( .* ) " / ) ;
668- if ( authenticityToken === null ) {
669- return cb ( 'Get LinkedIn token failed' ) ;
675+ const csrfToken = body . match ( / i n p u t t y p e = " h i d d e n " n a m e = " c s r f T o k e n " v a l u e = " ( .* ?) " / ) ;
676+ const loginCsrfToken = body . match ( / i n p u t t y p e = " h i d d e n " n a m e = " l o g i n C s r f P a r a m " v a l u e = " ( .* ?) " / ) ;
677+ const sIdString = body . match ( / i n p u t t y p e = " h i d d e n " n a m e = " s I d S t r i n g " v a l u e = " ( .* ?) " / ) ;
678+ const pageInstance = body . match ( / i n p u t t y p e = " h i d d e n " n a m e = " p a g e I n s t a n c e " v a l u e = " ( .* ?) " / ) ;
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