Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Auth Success Page #100

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/auth/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>CalendarSync</title>
</head>
<body style='font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;'>
<div style="text-align: center; padding-top: 30px;">
<h2 style="color:#051c59; font-weight: 500; font-size: 30px; margin-bottom: 10px;">CalendarSync authentication successful!</h2>
<p style="font-size:20px; color:#172e9a; margin-top: 10px;">You can now close this window.</p>
</div>
<div style="text-align: center; padding-top: 30px;">
<p style="font-size:15px; color:#051c59; margin-top: 20px;">The CalendarSync project is powered by:</p>
<a href="https://inovex.de"><img src="assets/inovex.png" height="100px"></a>
</div>
</body>
</html>
Binary file added internal/auth/assets/inovex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 11 additions & 14 deletions internal/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"context"
"embed"
"net"
"net/http"
"net/url"
Expand All @@ -12,18 +13,8 @@ import (
"golang.org/x/oauth2"
)

const successHtml = `<!DOCTYPE html>
<html>
<head>
<title>CalendarSync</title>
</head>
<body style='font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;'>
<div style="text-align: center; padding-top: 30px;">
<h2 style="color:#0fad00; font-weight: 500; font-size: 30px; margin-bottom: 10px;">CalendarSync authentication successful!</h2>
<p style="font-size:20px; color:#5C5C5C; margin-top: 10px;">You can now close this window.</p>
</div>
</body>
</html>`
//go:embed assets
var assets embed.FS

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

// show the user a success page and stop the http listener
w.WriteHeader(http.StatusOK)
if _, err := w.Write([]byte(successHtml)); err != nil {
panic(err)
successPage, err := assets.ReadFile("assets/index.html")
if err != nil {
log.Fatal("could not load auth success page", err)
}
_, err = w.Write(successPage)
if err != nil {
log.Fatal(err)
}
}
}
Expand All @@ -96,6 +92,7 @@ func (l *OAuthHandler) createAuthorizationExchange(ctx context.Context) func(htt
// and the http server will shut down.
func (l *OAuthHandler) Listen(ctx context.Context) error {
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.FS(assets)))
mux.HandleFunc("/redirect", l.createAuthorizationExchange(ctx))

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