AuthorizationRequestServer.py 1.4 KB

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