diff options
-rw-r--r-- | main.go | 24 | ||||
-rw-r--r-- | tmpl/index_login.tmpl | 2 |
2 files changed, 17 insertions, 9 deletions
@@ -22,6 +22,7 @@ package main import ( "errors" + "fmt" "html/template" "log" "net" @@ -37,12 +38,26 @@ var tmpl *template.Template func handle_index(w http.ResponseWriter, req *http.Request) { session_cookie, err := req.Cookie("session") if errors.Is(err, http.ErrNoCookie) { - err = tmpl.ExecuteTemplate(w, "index_login", nil) + err = tmpl.ExecuteTemplate( + w, + "index_login", + map[string]string{ + "authUrl": generate_authorization_url(), + }, + ) if err != nil { log.Println(err) return } return + } else if err != nil { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.WriteHeader(400) + w.Write([]byte(fmt.Sprintf( + "Error\n" + + "Unable to check cookie.", + ))) + return } _ = session_cookie err = tmpl.ExecuteTemplate(w, "index", nil) @@ -52,12 +67,6 @@ func handle_index(w http.ResponseWriter, req *http.Request) { } } -func handle_login(w http.ResponseWriter, req *http.Request) { - /* TODO: Invalidate current session */ - openid_authorization_url := generate_authorization_url() - http.Redirect(w, req, openid_authorization_url, 303) -} - func main() { /* * This seems necessary because in the following sections I need to @@ -83,7 +92,6 @@ func main() { log.Printf("Registering handlers\n") http.HandleFunc("/{$}", handle_index) - http.HandleFunc("/login", handle_login) http.HandleFunc("/oidc", handle_oidc) log.Printf("Fetching OpenID Connect configuration\n") diff --git a/tmpl/index_login.tmpl b/tmpl/index_login.tmpl index d9b997c..07fe8cb 100644 --- a/tmpl/index_login.tmpl +++ b/tmpl/index_login.tmpl @@ -28,7 +28,7 @@ You have not authenticated. </p> <p> - You must <a href="login">login</a> to use this service. + You must <a href="{{- .authUrl -}}">login</a> to use this service. </p> </body> </html> |