@@ -617,35 +617,14 @@ private function loginWithToken($token) {
617617 // Ignore and use empty string instead
618618 }
619619
620+ $ this ->manager ->emit ('\OC\User ' , 'preLogin ' , [$ dbToken ->getLoginName (), $ password ]);
621+
620622 $ user = $ this ->manager ->get ($ uid );
621623 if (is_null ($ user )) {
622- // Maybe this is an access token. We keep the refresh tokens as UID of access tokens
623- try {
624- $ token = $ uid ;
625- $ dbToken = $ this ->tokenProvider ->getToken ($ token );
626- } catch (InvalidTokenException $ ex ) {
627- return false ;
628- }
629- $ uid = $ dbToken ->getUID ();
630-
631- // When logging in with token, the password must be decrypted first before passing to login hook
632- $ password = '' ;
633- try {
634- $ password = $ this ->tokenProvider ->getPassword ($ dbToken , $ token );
635- } catch (PasswordlessTokenException $ ex ) {
636- // Ignore and use empty string instead
637- }
638624 // user does not exist
639- $ user = $ this ->manager ->get ($ uid );
640- if (is_null ($ user )) {
641- return false ;
642- }
625+ return false ;
643626 }
644627
645- $ this ->manager ->emit ('\OC\User ' , 'preLogin ' , [$ dbToken ->getLoginName (), $ password ]);
646-
647- // See line 173 in this module, needed for completeLogin
648- OC_User::setIncognitoMode (false );
649628 return $ this ->completeLogin (
650629 $ user ,
651630 [
@@ -867,30 +846,18 @@ public function tryTokenLogin(IRequest $request) {
867846 return false ;
868847 }
869848
870- return $ this ->doTryTokenLogin ($ token );
871- }
872-
873- private function doTryTokenLogin (string $ token ): bool {
874849 if (!$ this ->loginWithToken ($ token )) {
875850 return false ;
876851 }
877852 if (!$ this ->validateToken ($ token )) {
878853 return false ;
879854 }
880855
881- try {
882- $ dbToken = $ this ->tokenProvider ->getToken ($ token );
883- } catch (InvalidTokenException $ e ) {
884- // Can't really happen but better save than sorry
885- return true ;
886- }
887-
888856 // Set the session variable so we know this is an app password
889857 if ($ dbToken instanceof PublicKeyToken && $ dbToken ->getType () === IToken::PERMANENT_TOKEN ) {
890858 $ this ->session ->set ('app_password ' , $ token );
891859 } elseif ($ dbToken instanceof PublicKeyToken && $ dbToken ->getType () === IToken::ONETIME_TOKEN ) {
892860 $ this ->tokenProvider ->invalidateTokenById ($ dbToken ->getUID (), $ dbToken ->getId ());
893- $ request = \OCP \Server::get (IRequest::class);
894861 if ($ request ->getPathInfo () !== '/core/getapppassword-onetime ' ) {
895862 return false ;
896863 }
0 commit comments