diff --git a/cura/OAuth2/AuthorizationHelpers.py b/cura/OAuth2/AuthorizationHelpers.py index 7b7f58e74f..77e3c66c11 100644 --- a/cura/OAuth2/AuthorizationHelpers.py +++ b/cura/OAuth2/AuthorizationHelpers.py @@ -94,12 +94,12 @@ class AuthorizationHelpers: return callback(AuthenticationResponse(success = True, - token_type = token_data["token_type"], - access_token = token_data["access_token"], - refresh_token = token_data["refresh_token"], - expires_in = token_data["expires_in"], - scope = token_data["scope"], - received_at = datetime.now().strftime(TOKEN_TIMESTAMP_FORMAT))) + token_type = token_data["token_type"], + access_token = token_data["access_token"], + refresh_token = token_data["refresh_token"], + expires_in = token_data["expires_in"], + scope = token_data["scope"], + received_at = datetime.now().strftime(TOKEN_TIMESTAMP_FORMAT))) return def checkToken(self, access_token: str, success_callback: Optional[Callable[[UserProfile], None]] = None, failed_callback: Optional[Callable[[], None]] = None) -> None: diff --git a/cura/OAuth2/AuthorizationRequestHandler.py b/cura/OAuth2/AuthorizationRequestHandler.py index 59b3bafa98..f303980e3c 100644 --- a/cura/OAuth2/AuthorizationRequestHandler.py +++ b/cura/OAuth2/AuthorizationRequestHandler.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: catalog = i18nCatalog("cura") + class AuthorizationRequestHandler(BaseHTTPRequestHandler): """This handler handles all HTTP requests on the local web server. diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 03d1640659..38ecd1e823 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -25,6 +25,7 @@ if TYPE_CHECKING: MYCLOUD_LOGOFF_URL = "https://account.ultimaker.com/logoff?utm_source=cura&utm_medium=software&utm_campaign=change-account-before-adding-printers" + class AuthorizationService: """The authorization service is responsible for handling the login flow, storing user credentials and providing account information. @@ -62,7 +63,7 @@ class AuthorizationService: if self._preferences: self._preferences.addPreference(self._settings.AUTH_DATA_PREFERENCE_KEY, "{}") - def getUserProfile(self, callback: Callable[[Optional["UserProfile"]], None] = None) -> None: + def getUserProfile(self, callback: Optional[Callable[[Optional["UserProfile"]], None]] = None) -> None: """ Get the user profile as obtained from the JWT (JSON Web Token). @@ -79,7 +80,7 @@ class AuthorizationService: return # If no user profile was stored locally, we try to get it from JWT. - def store_profile(profile: Optional["UserProfile"]): + def store_profile(profile: Optional["UserProfile"]) -> None: if profile is not None: self._user_profile = profile if callback is not None: @@ -110,7 +111,7 @@ class AuthorizationService: return # When we checked the token we may get a user profile. This callback checks if that is a valid one and tries to refresh the token if it's not. - def check_user_profile(user_profile): + def check_user_profile(user_profile: Optional["UserProfile"]) -> None: if user_profile: # If the profile was found, we call it back immediately. callback(user_profile) @@ -121,7 +122,7 @@ class AuthorizationService: callback(None) return - def process_auth_data(auth_data: AuthenticationResponse): + def process_auth_data(auth_data: AuthenticationResponse) -> None: if auth_data.access_token is None: Logger.warning("Unable to use the refresh token to get a new access token.") callback(None) @@ -161,7 +162,7 @@ class AuthorizationService: Logger.log("w", "Unable to refresh access token, since there is no refresh token.") return - def process_auth_data(response: AuthenticationResponse): + def process_auth_data(response: AuthenticationResponse) -> None: if response.success: self._storeAuthData(response) self.onAuthStateChanged.emit(logged_in = True) @@ -264,7 +265,7 @@ class AuthorizationService: self._auth_data = AuthenticationResponse(**preferences_data) # Also check if we can actually get the user profile information. - def callback(profile: Optional["UserProfile"]): + def callback(profile: Optional["UserProfile"]) -> None: if profile is not None: self.onAuthStateChanged.emit(logged_in = True) Logger.debug("Auth data was successfully loaded") @@ -272,7 +273,8 @@ class AuthorizationService: if self._unable_to_get_data_message is not None: self._unable_to_get_data_message.show() else: - self._unable_to_get_data_message = Message(i18n_catalog.i18nc("@info", "Unable to reach the Ultimaker account server."), + self._unable_to_get_data_message = Message(i18n_catalog.i18nc("@info", + "Unable to reach the Ultimaker account server."), title = i18n_catalog.i18nc("@info:title", "Log-in failed"), message_type = Message.MessageType.ERROR) Logger.warning("Unable to get user profile using auth data from preferences.")