From 26e904b5e9840757bb3b6766afeca338e97c3f41 Mon Sep 17 00:00:00 2001 From: knotteye Date: Sun, 25 Apr 2021 16:13:59 -0500 Subject: [PATCH] Ask for new 2fa codes when one doesn't work --- pleroma.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pleroma.py b/pleroma.py index 306dd61..261c47b 100644 --- a/pleroma.py +++ b/pleroma.py @@ -86,14 +86,19 @@ class Account(): response = self.apiRequest('POST', '/oauth/token', request_data) if 'error' in response and response['error'] == 'mfa_required': if response['supported_challenge_types'] == 'totp' or 'totp' in response['supported_challenge_types']: - mfa_code, code_type = self.totpFunc(self, response['supported_challenge_types']) - response = self.apiRequest('POST', '/oauth/mfa/challenge', { - 'client_id': self.clientID, - 'client_secret': self.clientSecret, - 'mfa_token': response['mfa_token'], - 'challenge_type': code_type, - 'code': mfa_code - }) + ctypes = response['supported_challenge_types'] + mfa_token = response['mfa_token'] + while True: + mfa_code, code_type = self.totpFunc(self, ctypes) + response = self.apiRequest('POST', '/oauth/mfa/challenge', { + 'client_id': self.clientID, + 'client_secret': self.clientSecret, + 'mfa_token': mfa_token, + 'challenge_type': code_type, + 'code': mfa_code + }) + if not 'error' in response: + break elif 'error' in response: raise ValueError self.token = response['access_token']