def refresh_session(self): session_id = self.get_ru_tax_session() if not session_id: logging.info(self.tr("No valid session present")) return SlipsTaxAPI.Failure logging.info(self.tr("Refreshing session...")) client_secret = JalSettings().getValue('RuTaxClientSecret') refresh_token = JalSettings().getValue('RuTaxRefreshToken') self.web_session.headers['sessionId'] = session_id payload = '{' + f'"client_secret":"{client_secret}","refresh_token":"{refresh_token}"' + '}' response = self.web_session.post( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/refresh', data=payload) if response.status_code == 200: logging.info(self.tr("Session refreshed: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) return SlipsTaxAPI.Pending # not Success as it is sent transparently to upper callers else: logging.error( self.tr("Can't refresh session, response: ") + f"{response}/{response.text}") JalSettings().setValue('RuTaxSessionId', '') if self.get_ru_tax_session(): return SlipsTaxAPI.Failure else: return SlipsTaxAPI.Pending # not Success as it is sent transparently to upper callers
def login_fns(self): client_secret = JalSettings().getValue('RuTaxClientSecret') inn = self.InnEdit.text() password = self.PasswordEdit.text() s = requests.Session() s.headers['ClientVersion'] = '2.9.0' s.headers['Device-Id'] = str(uuid.uuid1()) s.headers['Device-OS'] = 'Android' s.headers['Content-Type'] = 'application/json; charset=UTF-8' s.headers['Accept-Encoding'] = 'gzip' s.headers['User-Agent'] = 'okhttp/4.2.2' payload = '{' + f'"client_secret":"{client_secret}","inn":"{inn}","password":"******"' + '}' response = s.post( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/lkfl/auth', data=payload) if response.status_code != 200: logging.error( g_tr('SlipsTaxAPI', "FNS login failed: ") + f"{response}/{response.text}") return logging.info( g_tr('SlipsTaxAPI', "FNS login successful: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) self.accept()
def refresh_session(self): logging.info(g_tr('SlipsTaxAPI', "Refreshing session...")) session_id = self.get_ru_tax_session() client_secret = JalSettings().getValue('RuTaxClientSecret') refresh_token = JalSettings().getValue('RuTaxRefreshToken') s = requests.Session() s.headers['ClientVersion'] = '2.9.0' s.headers['Device-Id'] = str(uuid.uuid1()) s.headers['Device-OS'] = 'Android' s.headers['sessionId'] = session_id s.headers['Content-Type'] = 'application/json; charset=UTF-8' s.headers['Accept-Encoding'] = 'gzip' s.headers['User-Agent'] = 'okhttp/4.2.2' payload = '{' + f'"client_secret":"{client_secret}","refresh_token":"{refresh_token}"' + '}' response = s.post( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/refresh', data=payload) if response.status_code == 200: logging.info( g_tr('SlipsTaxAPI', "Session refreshed: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) return SlipsTaxAPI.Pending # not Success as it is sent transparently to upper callers else: logging.error( g_tr('SlipsTaxAPI', "Can't refresh session, response: ") + f"{response}/{response.text}") return SlipsTaxAPI.Failure
def response_esia(self, auth_code, state): client_secret = JalSettings().getValue('RuTaxClientSecret') payload = '{' + f'"authorization_code": "{auth_code}", "client_secret": "{client_secret}", "state": "{state}"' \ + '}' response = self.web_session.post( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/esia/auth', data=payload) if response.status_code != 200: logging.error( self.tr("ESIA login failed: ") + f"{response}/{response.text}") return logging.info(self.tr("ESIA login successful: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) self.accept()
def login_fns(self): client_secret = JalSettings().getValue('RuTaxClientSecret') inn = self.InnEdit.text() password = self.PasswordEdit.text() payload = '{' + f'"client_secret":"{client_secret}","inn":"{inn}","password":"******"' + '}' response = self.web_session.post( 'https://irkkt-mobile.nalog.ru:8888/v2/mobile/users/lkfl/auth', data=payload) if response.status_code != 200: logging.error( self.tr("FNS login failed: ") + f"{response}/{response.text}") return logging.info(self.tr("FNS login successful: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) self.accept()
def login_sms(self): if not self.phone_number: return client_secret = JalSettings().getValue('RuTaxClientSecret') code = self.CodeEdit.text() payload = '{' + f'"client_secret":"{client_secret}","code":"{code}","phone":"{self.phone_number}"' + '}' response = self.web_session.post( 'https://irkkt-mobile.nalog.ru:8888/v2/auth/phone/verify', data=payload) if response.status_code != 200: logging.error( self.tr("FNS login failed: ") + f"{response}/{response.text}") return logging.info(self.tr("FNS login successful: ") + f"{response.text}") json_content = json.loads(response.text) new_session_id = json_content['sessionId'] new_refresh_token = json_content['refresh_token'] settings = JalSettings() settings.setValue('RuTaxSessionId', new_session_id) settings.setValue('RuTaxRefreshToken', new_refresh_token) self.accept()