mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-21 21:58:01 -06:00
Fix situation where authtoken wasnt updated for the toolbox request headers
This commit is contained in:
parent
078707a726
commit
5f76070f05
3 changed files with 11 additions and 1 deletions
|
@ -29,6 +29,7 @@ i18n_catalog = i18nCatalog("cura")
|
||||||
class Account(QObject):
|
class Account(QObject):
|
||||||
# Signal emitted when user logged in or out.
|
# Signal emitted when user logged in or out.
|
||||||
loginStateChanged = pyqtSignal(bool)
|
loginStateChanged = pyqtSignal(bool)
|
||||||
|
accessTokenChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, application: "CuraApplication", parent = None) -> None:
|
def __init__(self, application: "CuraApplication", parent = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
@ -59,8 +60,12 @@ class Account(QObject):
|
||||||
self._authorization_service.initialize(self._application.getPreferences())
|
self._authorization_service.initialize(self._application.getPreferences())
|
||||||
self._authorization_service.onAuthStateChanged.connect(self._onLoginStateChanged)
|
self._authorization_service.onAuthStateChanged.connect(self._onLoginStateChanged)
|
||||||
self._authorization_service.onAuthenticationError.connect(self._onLoginStateChanged)
|
self._authorization_service.onAuthenticationError.connect(self._onLoginStateChanged)
|
||||||
|
self._authorization_service.accessTokenChanged.connect(self._onAccessTokenChanged)
|
||||||
self._authorization_service.loadAuthDataFromPreferences()
|
self._authorization_service.loadAuthDataFromPreferences()
|
||||||
|
|
||||||
|
def _onAccessTokenChanged(self):
|
||||||
|
self.accessTokenChanged.emit()
|
||||||
|
|
||||||
## Returns a boolean indicating whether the given authentication is applied against staging or not.
|
## Returns a boolean indicating whether the given authentication is applied against staging or not.
|
||||||
@property
|
@property
|
||||||
def is_staging(self) -> bool:
|
def is_staging(self) -> bool:
|
||||||
|
@ -105,7 +110,7 @@ class Account(QObject):
|
||||||
return None
|
return None
|
||||||
return user_profile.profile_image_url
|
return user_profile.profile_image_url
|
||||||
|
|
||||||
@pyqtProperty(str, notify=loginStateChanged)
|
@pyqtProperty(str, notify=accessTokenChanged)
|
||||||
def accessToken(self) -> Optional[str]:
|
def accessToken(self) -> Optional[str]:
|
||||||
return self._authorization_service.getAccessToken()
|
return self._authorization_service.getAccessToken()
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ class AuthorizationService:
|
||||||
# Emit signal when authentication failed.
|
# Emit signal when authentication failed.
|
||||||
onAuthenticationError = Signal()
|
onAuthenticationError = Signal()
|
||||||
|
|
||||||
|
accessTokenChanged = Signal()
|
||||||
|
|
||||||
def __init__(self, settings: "OAuth2Settings", preferences: Optional["Preferences"] = None) -> None:
|
def __init__(self, settings: "OAuth2Settings", preferences: Optional["Preferences"] = None) -> None:
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._auth_helpers = AuthorizationHelpers(settings)
|
self._auth_helpers = AuthorizationHelpers(settings)
|
||||||
|
@ -214,6 +216,8 @@ class AuthorizationService:
|
||||||
self._user_profile = None
|
self._user_profile = None
|
||||||
self._preferences.resetPreference(self._settings.AUTH_DATA_PREFERENCE_KEY)
|
self._preferences.resetPreference(self._settings.AUTH_DATA_PREFERENCE_KEY)
|
||||||
|
|
||||||
|
self.accessTokenChanged.emit()
|
||||||
|
|
||||||
def _onMessageActionTriggered(self, _, action):
|
def _onMessageActionTriggered(self, _, action):
|
||||||
if action == "retry":
|
if action == "retry":
|
||||||
self.loadAuthDataFromPreferences()
|
self.loadAuthDataFromPreferences()
|
||||||
|
|
|
@ -105,6 +105,7 @@ class Toolbox(QObject, Extension):
|
||||||
|
|
||||||
self._application.initializationFinished.connect(self._onAppInitialized)
|
self._application.initializationFinished.connect(self._onAppInitialized)
|
||||||
self._application.getCuraAPI().account.loginStateChanged.connect(self._updateRequestHeader)
|
self._application.getCuraAPI().account.loginStateChanged.connect(self._updateRequestHeader)
|
||||||
|
self._application.getCuraAPI().account.accessTokenChanged.connect(self._updateRequestHeader)
|
||||||
|
|
||||||
# Signals:
|
# Signals:
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue