AuthorizationRequestServer.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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 socketserver import ThreadingMixIn
  5. from typing import Callable, Any, TYPE_CHECKING
  6. if TYPE_CHECKING:
  7. from cura.OAuth2.Models import AuthenticationResponse
  8. from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers
  9. class AuthorizationRequestServer(ThreadingMixIn, HTTPServer):
  10. """The authorization request callback handler server.
  11. This subclass is needed to be able to pass some data to the request handler. This cannot be done on the request
  12. handler directly as the HTTPServer creates an instance of the handler after init.
  13. """
  14. def setAuthorizationHelpers(self, authorization_helpers: "AuthorizationHelpers") -> None:
  15. """Set the authorization helpers instance on the request handler."""
  16. self.RequestHandlerClass.authorization_helpers = authorization_helpers # type: ignore
  17. def setAuthorizationCallback(self, authorization_callback: Callable[["AuthenticationResponse"], Any]) -> None:
  18. """Set the authorization callback on the request handler."""
  19. self.RequestHandlerClass.authorization_callback = authorization_callback # type: ignore
  20. def setVerificationCode(self, verification_code: str) -> None:
  21. """Set the verification code on the request handler."""
  22. self.RequestHandlerClass.verification_code = verification_code # type: ignore
  23. def setState(self, state: str) -> None:
  24. self.RequestHandlerClass.state = state # type: ignore