mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 19:05:51 +08:00
Call getAccessTokenUsingRefreshToken asynchronously
Getting into nested inline functions into inline functions here. Let's see what the reviewer thinks of all this! Contributes to issue CURA-8539.
This commit is contained in:
parent
7091c5f3aa
commit
9895015235
@ -115,17 +115,20 @@ class AuthorizationService:
|
|||||||
Logger.warning("There was no refresh token in the auth data.")
|
Logger.warning("There was no refresh token in the auth data.")
|
||||||
callback(None)
|
callback(None)
|
||||||
return
|
return
|
||||||
self._auth_data = self._auth_helpers.getAccessTokenUsingRefreshToken(self._auth_data.refresh_token) # TODO: Blocks main thread, preventing HttpRequestManager from functioning?
|
|
||||||
if not self._auth_data or self._auth_data.access_token is None:
|
def process_auth_data(auth_data: AuthenticationResponse):
|
||||||
Logger.warning("Unable to use the refresh token to get a new access token.")
|
if auth_data.access_token is None:
|
||||||
callback(None)
|
Logger.warning("Unable to use the refresh token to get a new access token.")
|
||||||
return
|
callback(None)
|
||||||
# Ensure it gets stored as otherwise we only have it in memory. The stored refresh token has been deleted
|
return
|
||||||
# from the server already. Do not store the auth_data if we could not get new auth_data (e.g. due to a
|
# Ensure it gets stored as otherwise we only have it in memory. The stored refresh token has been
|
||||||
# network error), since this would cause an infinite loop trying to get new auth-data.
|
# deleted from the server already. Do not store the auth_data if we could not get new auth_data (e.g.
|
||||||
if self._auth_data.success:
|
# due to a network error), since this would cause an infinite loop trying to get new auth-data.
|
||||||
self._storeAuthData(self._auth_data)
|
if auth_data.success:
|
||||||
self._auth_helpers.checkToken(self._auth_data.access_token, callback, lambda: callback(None))
|
self._storeAuthData(auth_data)
|
||||||
|
self._auth_helpers.checkToken(auth_data.access_token, callback, lambda: callback(None))
|
||||||
|
|
||||||
|
self._auth_helpers.getAccessTokenUsingRefreshToken(self._auth_data.refresh_token, process_auth_data)
|
||||||
|
|
||||||
self._auth_helpers.checkToken(self._auth_data.access_token, check_user_profile)
|
self._auth_helpers.checkToken(self._auth_data.access_token, check_user_profile)
|
||||||
|
|
||||||
@ -152,13 +155,16 @@ class AuthorizationService:
|
|||||||
if self._auth_data is None or self._auth_data.refresh_token is None:
|
if self._auth_data is None or self._auth_data.refresh_token is None:
|
||||||
Logger.log("w", "Unable to refresh access token, since there is no refresh token.")
|
Logger.log("w", "Unable to refresh access token, since there is no refresh token.")
|
||||||
return
|
return
|
||||||
response = self._auth_helpers.getAccessTokenUsingRefreshToken(self._auth_data.refresh_token)
|
|
||||||
if response.success:
|
def process_auth_data(response: AuthenticationResponse):
|
||||||
self._storeAuthData(response)
|
if response.success:
|
||||||
self.onAuthStateChanged.emit(logged_in = True)
|
self._storeAuthData(response)
|
||||||
else:
|
self.onAuthStateChanged.emit(logged_in = True)
|
||||||
Logger.log("w", "Failed to get a new access token from the server.")
|
else:
|
||||||
self.onAuthStateChanged.emit(logged_in = False)
|
Logger.warning("Failed to get a new access token from the server.")
|
||||||
|
self.onAuthStateChanged.emit(logged_in = False)
|
||||||
|
|
||||||
|
self._auth_helpers.getAccessTokenUsingRefreshToken(self._auth_data.refresh_token, process_auth_data)
|
||||||
|
|
||||||
def deleteAuthData(self) -> None:
|
def deleteAuthData(self) -> None:
|
||||||
"""Delete the authentication data that we have stored locally (eg; logout)"""
|
"""Delete the authentication data that we have stored locally (eg; logout)"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user