def _handleCallback( self, query: Dict[Any, List] ) -> Tuple[ResponseData, Optional[AuthenticationResponse]]: code = self._queryGet(query, "code") if code and self.authorization_helpers is not None and self.verification_code is not None: # If the code was returned we get the access token. token_response = self.authorization_helpers.getAccessTokenUsingAuthorizationCode( code, self.verification_code) elif self._queryGet(query, "error_code") == "user_denied": # Otherwise we show an error message (probably the user clicked "Deny" in the auth dialog). token_response = AuthenticationResponse( success=False, err_message= "Please give the required permissions when authorizing this application." ) else: # We don't know what went wrong here, so instruct the user to check the logs. token_response = AuthenticationResponse( success=False, error_message= "Something unexpected happened when trying to log in, please try again." ) if self.authorization_helpers is None: return ResponseData(), token_response return ResponseData(status=HTTP_STATUS["REDIRECT"], data_stream=b"Redirecting...", redirect_uri=self.authorization_helpers.settings. AUTH_SUCCESS_REDIRECT if token_response.success else self.authorization_helpers.settings. AUTH_FAILED_REDIRECT), token_response
def _handleCallback( self, query: Dict[Any, List] ) -> Tuple[ResponseData, Optional[AuthenticationResponse]]: """Handler for the callback URL redirect. :param query: Dict containing the HTTP query parameters. :return: HTTP ResponseData containing a success page to show to the user. """ code = self._queryGet(query, "code") state = self._queryGet(query, "state") if state != self.state: token_response = AuthenticationResponse( success=False, err_message=catalog.i18nc( "@message", "The provided state is not correct.")) elif code and self.authorization_helpers is not None and self.verification_code is not None: token_response = AuthenticationResponse( success=False, err_message=catalog.i18nc( "@message", "Timeout when authenticating with the account server.")) # If the code was returned we get the access token. lock = Lock() lock.acquire() def callback(response: AuthenticationResponse) -> None: nonlocal token_response token_response = response lock.release() self.authorization_helpers.getAccessTokenUsingAuthorizationCode( code, self.verification_code, callback) lock.acquire( timeout=60 ) # Block thread until request is completed (which releases the lock). If not acquired, the timeout message stays. elif self._queryGet(query, "error_code") == "user_denied": # Otherwise we show an error message (probably the user clicked "Deny" in the auth dialog). token_response = AuthenticationResponse( success=False, err_message=catalog.i18nc( "@message", "Please give the required permissions when authorizing this application." )) else: # We don't know what went wrong here, so instruct the user to check the logs. token_response = AuthenticationResponse( success=False, error_message=catalog.i18nc( "@message", "Something unexpected happened when trying to log in, please try again." )) if self.authorization_helpers is None: return ResponseData(), token_response return ResponseData(status=HTTP_STATUS["REDIRECT"], data_stream=b"Redirecting...", redirect_uri=self.authorization_helpers.settings. AUTH_SUCCESS_REDIRECT if token_response.success else self.authorization_helpers.settings. AUTH_FAILED_REDIRECT), token_response
def _handleNotFound() -> ResponseData: """Handle all other non-existing server calls.""" return ResponseData(status=HTTP_STATUS["NOT_FOUND"], content_type="text/html", data_stream=b"Not found.")
def _handleNotFound() -> ResponseData: return ResponseData(status=HTTP_STATUS["NOT_FOUND"], content_type="text/html", data_stream=b"Not found.")