Skip to content

Commit

Permalink
Merge pull request #100 from inovex/new-auth-design
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr13 authored Nov 23, 2023
2 parents b4d7062 + 32238a4 commit 5ab4544
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
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

0 comments on commit 5ab4544

Please sign in to comment.