AuthorizationRequestServer.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from http.server import HTTPServer
  4. from typing import Callable, Any, TYPE_CHECKING
  5. if TYPE_CHECKING:
  6. from cura.OAuth2.Models import AuthenticationResponse
  7. from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers
  8. class AuthorizationRequestServer(HTTPServer):
  9. """The authorization request callback handler server.
  10. This subclass is needed to be able to pass some data to the request handler. This cannot be done on the request
  11. handler directly as the HTTPServer creates an instance of the handler after init.
  12. """
  13. def setAuthorizationHelpers(self, authorization_helpers: "AuthorizationHelpers") -> None:
  14. """Set the authorization helpers instance on the request handler."""
  15. self.RequestHandlerClass.authorization_helpers = authorization_helpers # type: ignore
  16. def setAuthorizationCallback(self, authorization_callback: Callable[["AuthenticationResponse"], Any]) -> None:
  17. """Set the authorization callback on the request handler."""
  18. self.RequestHandlerClass.authorization_callback = authorization_callback # type: ignore
  19. def setVerificationCode(self, verification_code: str) -> None:
  20. """Set the verification code on the request handler."""
  21. self.RequestHandlerClass.verification_code = verification_code # type: ignore
  22. def setState(self, state: str) -> None:
  23. self.RequestHandlerClass.state = state # type: ignore