Skip to content

Commit 5ab4544

Browse files
authored
Merge pull request #100 from inovex/new-auth-design
2 parents b4d7062 + 32238a4 commit 5ab4544

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

internal/auth/assets/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>CalendarSync</title>
5+
</head>
6+
<body style='font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;'>
7+
<div style="text-align: center; padding-top: 30px;">
8+
<h2 style="color:#051c59; font-weight: 500; font-size: 30px; margin-bottom: 10px;">CalendarSync authentication successful!</h2>
9+
<p style="font-size:20px; color:#172e9a; margin-top: 10px;">You can now close this window.</p>
10+
</div>
11+
<div style="text-align: center; padding-top: 30px;">
12+
<p style="font-size:15px; color:#051c59; margin-top: 20px;">The CalendarSync project is powered by:</p>
13+
<a href="https://inovex.de"><img src="assets/inovex.png" height="100px"></a>
14+
</div>
15+
</body>
16+
</html>

internal/auth/assets/inovex.png

17.3 KB
Loading

internal/auth/handler.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package auth
22

33
import (
44
"context"
5+
"embed"
56
"net"
67
"net/http"
78
"net/url"
@@ -12,18 +13,8 @@ import (
1213
"golang.org/x/oauth2"
1314
)
1415

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
2718

2819
type OAuthHandler struct {
2920
listener net.Listener
@@ -86,8 +77,13 @@ func (l *OAuthHandler) createAuthorizationExchange(ctx context.Context) func(htt
8677

8778
// show the user a success page and stop the http listener
8879
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)
9187
}
9288
}
9389
}
@@ -96,6 +92,7 @@ func (l *OAuthHandler) createAuthorizationExchange(ctx context.Context) func(htt
9692
// and the http server will shut down.
9793
func (l *OAuthHandler) Listen(ctx context.Context) error {
9894
mux := http.NewServeMux()
95+
mux.Handle("/", http.FileServer(http.FS(assets)))
9996
mux.HandleFunc("/redirect", l.createAuthorizationExchange(ctx))
10097

10198
if err := http.Serve(l.listener, mux); err != nil {

0 commit comments

Comments
 (0)