src/eric7/EricNetwork/EricGoogleMail.py

branch
eric7
changeset 9245
6ee1705a1cb9
parent 9221
bf71ee032bb4
child 9413
80c06d472826
equal deleted inserted replaced
9244:3bf1a02df07a 9245:6ee1705a1cb9
18 from requests_oauthlib import OAuth2Session 18 from requests_oauthlib import OAuth2Session
19 19
20 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject, QUrl, QUrlQuery 20 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject, QUrl, QUrlQuery
21 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout 21 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
22 22
23 from EricWidgets import EricMessageBox
23 from EricWidgets.EricTextInputDialog import EricTextInputDialog 24 from EricWidgets.EricTextInputDialog import EricTextInputDialog
24 25
25 import Globals 26 import Globals
26 27
27 from .EricGoogleMailHelpers import ( 28 from .EricGoogleMailHelpers import (
88 ): 89 ):
89 urlQuery = QUrlQuery(url) 90 urlQuery = QUrlQuery(url)
90 approvalCode = urlQuery.queryItemValue( 91 approvalCode = urlQuery.queryItemValue(
91 "approvalCode", QUrl.ComponentFormattingOption.FullyDecoded 92 "approvalCode", QUrl.ComponentFormattingOption.FullyDecoded
92 ) 93 )
93 if approvalCode: 94 elif url.toString().startswith(("http://localhost", "https://localhost")):
94 self.approvalCodeReceived.emit(approvalCode) 95 urlQuery = QUrlQuery(url)
95 self.close() 96 approvalCode = urlQuery.queryItemValue(
97 "code", QUrl.ComponentFormattingOption.FullyDecoded
98 )
99 else:
100 approvalCode = None
101 if approvalCode:
102 self.approvalCodeReceived.emit(approvalCode)
103 self.close()
96 104
97 def load(self, url): 105 def load(self, url):
98 """ 106 """
99 Public method to start the authorization flow by loading the given URL. 107 Public method to start the authorization flow by loading the given URL.
100 108
234 Private slot to process the received authorization code. 242 Private slot to process the received authorization code.
235 243
236 @param authCode received authorization code 244 @param authCode received authorization code
237 @type str 245 @type str
238 """ 246 """
239 self.__session.fetch_token( 247 try:
240 self.__clientConfig["token_uri"], 248 self.__session.fetch_token(
241 client_secret=self.__clientConfig["client_secret"], 249 self.__clientConfig["token_uri"],
242 code=authCode, 250 client_secret=self.__clientConfig["client_secret"],
243 ) 251 code=authCode,
244 self.__saveToken(self.__session.token) 252 )
245 253 self.__saveToken(self.__session.token)
246 # authorization completed; now send all queued messages 254
247 self.__doSendMessages() 255 # authorization completed; now send all queued messages
256 self.__doSendMessages()
257 except Exception as err:
258 EricMessageBox.critical(
259 self,
260 self.tr("Google Authorization"),
261 self.tr(
262 """<p>The authorization via Google failed.</p><p>Reason: {0}</p>"""
263 ).format(str(err)),
264 )
248 265
249 def __doSendMessages(self): 266 def __doSendMessages(self):
250 """ 267 """
251 Private method to send all queued messages. 268 Private method to send all queued messages.
252 """ 269 """

eric ide

mercurial