Skip to content

server

LoginServerHandler

Bases: BaseHTTPRequestHandler

Login server handler.

Source code in common/ayon_common/connection/ui/server.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class LoginServerHandler(BaseHTTPRequestHandler):
    """Login server handler."""

    def do_GET(self):
        """Override to handle requests ourselves."""
        if self.path == "/index.css":
            filepath = get_resource_path("index.css")
            with open(filepath, "rb") as stream:
                content = stream.read()
            content_type = "text/css"
        elif self.path == "/favicon.ico":
            filepath = get_resource_path("favicon.ico")
            with open(filepath, "rb") as stream:
                content = stream.read()
            content_type = "image/x-icon"
        else:
            parsed_path = urlparse(self.path)
            query = parse_qs(parsed_path.query)
            tokens = query.get("token")
            access_token = None
            if tokens:
                access_token = tokens[0]
            self.server.set_token(access_token)

            content_type = "text/html"
            if access_token:
                filepath = get_resource_path("success.html")
            else:
                filepath = get_resource_path("failed.html")
            with open(filepath, "rb") as stream:
                content = stream.read()

        # Set header with content type
        self.send_response(200)
        self.send_header("Content-type", content_type)
        self.end_headers()
        self.wfile.write(content)

    def log_message(self, *args, **kwargs):
        # Avoid crash in process without stderr
        # - e.g. UI build on windows
        if sys.stderr is not None:
            super().log_message(*args, **kwargs)

do_GET()

Override to handle requests ourselves.

Source code in common/ayon_common/connection/ui/server.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def do_GET(self):
    """Override to handle requests ourselves."""
    if self.path == "/index.css":
        filepath = get_resource_path("index.css")
        with open(filepath, "rb") as stream:
            content = stream.read()
        content_type = "text/css"
    elif self.path == "/favicon.ico":
        filepath = get_resource_path("favicon.ico")
        with open(filepath, "rb") as stream:
            content = stream.read()
        content_type = "image/x-icon"
    else:
        parsed_path = urlparse(self.path)
        query = parse_qs(parsed_path.query)
        tokens = query.get("token")
        access_token = None
        if tokens:
            access_token = tokens[0]
        self.server.set_token(access_token)

        content_type = "text/html"
        if access_token:
            filepath = get_resource_path("success.html")
        else:
            filepath = get_resource_path("failed.html")
        with open(filepath, "rb") as stream:
            content = stream.read()

    # Set header with content type
    self.send_response(200)
    self.send_header("Content-type", content_type)
    self.end_headers()
    self.wfile.write(content)