@@ -2,6 +2,7 @@ package auth
2
2
3
3
import (
4
4
"context"
5
+ "embed"
5
6
"net"
6
7
"net/http"
7
8
"net/url"
@@ -12,18 +13,8 @@ import (
12
13
"golang.org/x/oauth2"
13
14
)
14
15
15
- const successHtml = `<!DOCTYPE html>
16
- <html>
17
- <head>
18
- <title>CalendarSync</title>
19
- </head>
20
- <body style='font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;'>
21
- <div style="text-align: center; padding-top: 30px;">
22
- <h2 style="color:#0fad00; font-weight: 500; font-size: 30px; margin-bottom: 10px;">CalendarSync authentication successful!</h2>
23
- <p style="font-size:20px; color:#5C5C5C; margin-top: 10px;">You can now close this window.</p>
24
- </div>
25
- </body>
26
- </html>`
16
+ //go:embed assets
17
+ var assets embed.FS
27
18
28
19
type OAuthHandler struct {
29
20
listener net.Listener
@@ -86,8 +77,13 @@ func (l *OAuthHandler) createAuthorizationExchange(ctx context.Context) func(htt
86
77
87
78
// show the user a success page and stop the http listener
88
79
w .WriteHeader (http .StatusOK )
89
- if _ , err := w .Write ([]byte (successHtml )); err != nil {
90
- panic (err )
80
+ successPage , err := assets .ReadFile ("assets/index.html" )
81
+ if err != nil {
82
+ log .Fatal ("could not load auth success page" , err )
83
+ }
84
+ _ , err = w .Write (successPage )
85
+ if err != nil {
86
+ log .Fatal (err )
91
87
}
92
88
}
93
89
}
@@ -96,6 +92,7 @@ func (l *OAuthHandler) createAuthorizationExchange(ctx context.Context) func(htt
96
92
// and the http server will shut down.
97
93
func (l * OAuthHandler ) Listen (ctx context.Context ) error {
98
94
mux := http .NewServeMux ()
95
+ mux .Handle ("/" , http .FileServer (http .FS (assets )))
99
96
mux .HandleFunc ("/redirect" , l .createAuthorizationExchange (ctx ))
100
97
101
98
if err := http .Serve (l .listener , mux ); err != nil {
0 commit comments