13
13
import webbrowser
14
14
from collections .abc import Mapping
15
15
from enum import Enum
16
- from string import Template
17
16
from typing import Any , Optional , TypedDict , Union
18
17
from urllib .parse import urlencode , urlsplit , urlunsplit
19
18
@@ -587,14 +586,7 @@ class CallbackHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
587
586
</svg>"""
588
587
"""SVG to display error icon"""
589
588
590
- PAGE_TEMPLATE = Template (
591
- """
592
- <html lang="$lang">
593
- <head>
594
- <title>$title</title>
595
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
596
- <meta name="charset" content="utf-8">
597
- <style>
589
+ CSS_STYLE = """
598
590
* {
599
591
margin: 0;
600
592
padding: 0;
@@ -678,19 +670,40 @@ class CallbackHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
678
670
-webkit-animation: colored-circle 0.6s ease-in-out 0.7s backwards;
679
671
animation: colored-circle 0.6s ease-in-out 0.7s backwards;
680
672
}
681
- </style>
673
+ """
674
+
675
+ # NOTE: Rest of this code borrowed from `fief-python[cli]`
676
+ # https://github.com/fief-dev/fief-python/blob/main/fief_client/integrations/cli.py
677
+ def __init__ (
678
+ self ,
679
+ * args ,
680
+ queue : "queue.Queue[str]" ,
681
+ ** kwargs ,
682
+ ) -> None :
683
+ self .queue = queue
684
+ super ().__init__ (* args , ** kwargs )
685
+
686
+ def log_message (self , format : str , * args : typing .Any ) -> None :
687
+ pass
688
+
689
+ def render_success_page (self , lang = "en" ) -> str :
690
+ return f"""
691
+ <html lang="{ lang } ">
692
+ <head>
693
+ <title>Authentication Success</title>
694
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
695
+ <meta name="charset" content="utf-8">
696
+ <style>{ self .CSS_STYLE } </style>
682
697
</head>
683
698
684
699
<body>
685
700
<div class="message">
686
701
<div class="animation-ctn">
687
- <div class="icon">
688
- $svg
689
- </div>
702
+ <div class="icon">{ self .SUCCESS_SVG } </div>
690
703
</div>
691
704
692
- <h1>$title </h1>
693
- <p>$message </p>
705
+ <h1>Authentication Successful </h1>
706
+ <p>Done! You can go back to your terminal! This page will auto-close in 5 secs. </p>
694
707
</div>
695
708
</body>
696
709
<script>
@@ -702,39 +715,32 @@ class CallbackHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
702
715
</script>
703
716
</html>
704
717
"""
705
- )
706
- """Template for callback HTML page"""
707
718
708
- # NOTE: Rest of this code borrowed from `fief-python[cli]`
709
- # https://github.com/fief-dev/fief-python/blob/main/fief_client/integrations/cli.py
710
- def __init__ (
711
- self ,
712
- * args ,
713
- queue : "queue.Queue[str]" ,
714
- ** kwargs ,
715
- ) -> None :
716
- self .queue = queue
717
- super ().__init__ (* args , ** kwargs )
718
-
719
- def log_message (self , format : str , * args : typing .Any ) -> None :
720
- pass
719
+ def render_error_page (self , query_params : dict [str , typing .Any ], lang = "en" ) -> str :
720
+ return f"""
721
+ <html lang="{ lang } ">
722
+ <head>
723
+ <title>Authentication Failed</title>
724
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
725
+ <meta name="charset" content="utf-8">
726
+ <style>{ self .CSS_STYLE } </style>
727
+ </head>
721
728
722
- def render_success_page (self , lang = "en" ) -> str :
723
- return self .PAGE_TEMPLATE .substitute (
724
- lang = lang ,
725
- title = "Authentication Successful" ,
726
- message = "Done! You can go back to your terminal! This page will auto-close in 5 secs." ,
727
- svg = self .SUCCESS_SVG ,
728
- )
729
+ <body>
730
+ <div class="message">
731
+ <div class="animation-ctn">
732
+ <div class="icon">{ self .ERROR_SVG } </div>
733
+ </div>
729
734
730
- def render_error_page (self , query_params : dict [str , typing .Any ], lang = "en" ) -> str :
731
- return self .PAGE_TEMPLATE .substitute (
732
- lang = lang ,
733
- title = "Authentication Failed" ,
734
- message = f"""Something went wrong trying to authenticate your. Please try again.
735
- Error detail: { json .dumps (query_params )} """ ,
736
- svg = self .ERROR_SVG ,
737
- )
735
+ <h1>Authentication Failed</h1>
736
+ <p>
737
+ Something went wrong trying to authenticate you.
738
+ Please try again. Error detail: { json .dumps (query_params )}
739
+ </p>
740
+ </div>
741
+ </body>
742
+ </html>
743
+ """
738
744
739
745
def do_GET (self ):
740
746
parsed_url = urllib .parse .urlparse (self .path )
0 commit comments