@@ -540,30 +540,23 @@ plugin.login = function(user, cb) {
540
540
} ;
541
541
542
542
function parseCookie ( cookie , body , cb ) {
543
- const isCN = config . app === 'leetcode.cn' ;
544
543
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 = ( .+ ?) ( ; | $ ) / ;
552
545
const reSessionResult = SessionPattern . exec ( cookie ) ;
553
- const reCsrfResult = csrfPattern . exec ( isCN ? body : cookie ) ;
546
+ const reCsrfResult = csrfPattern . exec ( cookie ) ;
554
547
if ( reSessionResult === null || reCsrfResult === null ) {
555
548
return cb ( 'invalid cookie?' ) ;
556
549
}
557
550
return {
558
- sessionId : reSessionResult [ 1 ] ,
551
+ // sessionId: SessionResult[1],
552
+ sessionId : cookie ,
559
553
sessionCSRF : reCsrfResult [ 1 ] ,
560
554
} ;
561
555
}
562
556
563
557
function requestLeetcodeAndSave ( request , leetcodeUrl , user , cb ) {
564
558
request . get ( { url : leetcodeUrl } , function ( e , resp , body ) {
565
559
const redirectUri = resp . request . uri . href ;
566
- console . log ( redirectUri ) ;
567
560
if ( redirectUri !== config . sys . urls . leetcode_redirect ) {
568
561
return cb ( 'Login failed. Please make sure the credential is correct.' ) ;
569
562
}
@@ -589,9 +582,18 @@ plugin.githubLogin = function(user, cb) {
589
582
const _request = request . defaults ( { jar : true } ) ;
590
583
_request ( urls . github_login_request , function ( e , resp , body ) {
591
584
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 = " ( .* ?) " / ) ;
592
- if ( authenticityToken === null ) {
593
- return cb ( 'Get GitHub token failed' ) ;
585
+ let gaId = body . match ( / n a m e = " g a _ i d " v a l u e = " ( .* ?) " / ) ;
586
+ if ( ! gaId ) {
587
+ gaId = '' ;
588
+ }
589
+ let requiredField = body . match ( / n a m e = " r e q u i r e d _ f i e l d _ ( .* ?) " / ) ;
590
+ const timestamp = body . match ( / n a m e = " t i m e s t a m p " v a l u e = " ( .* ?) " / ) ;
591
+ 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 = " ( .* ?) " / ) ;
592
+
593
+ if ( ! ( authenticityToken && timestamp && timestampSecret && requiredField ) ) {
594
+ return cb ( 'Get GitHub payload failed' ) ;
594
595
}
596
+ requiredField = 'required_field_' + requiredField [ 1 ] ;
595
597
const options = {
596
598
url : urls . github_session_request ,
597
599
method : 'POST' ,
@@ -600,11 +602,17 @@ plugin.githubLogin = function(user, cb) {
600
602
} ,
601
603
followAllRedirects : true ,
602
604
form : {
603
- 'login' : user . login ,
604
- 'password' : user . pass ,
605
- 'authenticity_token' : authenticityToken [ 1 ] ,
606
- 'utf8' : encodeURIComponent ( '✓' ) ,
607
- 'commit' : encodeURIComponent ( 'Sign in' )
605
+ 'login' : user . login ,
606
+ 'password' : user . pass ,
607
+ 'authenticity_token' : authenticityToken [ 1 ] ,
608
+ 'commit' : encodeURIComponent ( 'Sign in' ) ,
609
+ 'ga_id' : gaId ,
610
+ 'webauthn-support' : 'supported' ,
611
+ 'webauthn-iuvpaa-support' : 'unsupported' ,
612
+ 'return_to' : '' ,
613
+ 'requiredField' : '' ,
614
+ 'timestamp' : timestamp [ 1 ] ,
615
+ 'timestamp_secret' : timestampSecret [ 1 ] ,
608
616
} ,
609
617
} ;
610
618
_request ( options , function ( e , resp , body ) {
0 commit comments