Implement oidc client of sorts
This commit is contained in:
parent
1772e57ee8
commit
a750f646a9
7 changed files with 175 additions and 55 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/auth"
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/middleware"
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/notes"
|
||||
|
|
@ -33,6 +34,7 @@ func main() {
|
|||
|
||||
router := http.NewServeMux()
|
||||
notesRouter := views.GetRoutes("/notes")
|
||||
authRouter := auth.GetRoutes("/auth", sessions.Login)
|
||||
|
||||
cacheExpiration, err := time.ParseDuration("24h")
|
||||
if err != nil {
|
||||
|
|
@ -41,31 +43,10 @@ func main() {
|
|||
|
||||
etag := middleware.NewETag("static", cacheExpiration)
|
||||
|
||||
if !conf.Conf.Production {
|
||||
router.HandleFunc("/login/", func(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.FormValue("user")
|
||||
if len(user) == 0 {
|
||||
user = "anon"
|
||||
}
|
||||
sessions.Login(user, w)
|
||||
|
||||
http.Redirect(w, r, "/notes/", http.StatusFound)
|
||||
})
|
||||
}
|
||||
router.Handle("/logout/", sessions.AsMiddleware(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.FormValue("user")
|
||||
if len(user) == 0 {
|
||||
user = "anon"
|
||||
}
|
||||
|
||||
sessions.Logout(w, r)
|
||||
|
||||
http.Redirect(w, r, "/notes/", http.StatusFound)
|
||||
})))
|
||||
|
||||
router.Handle("/logout/", sessions.AsMiddleware(middleware.LoggingMiddleware(http.HandlerFunc(sessions.Logout))))
|
||||
router.Handle("/", middleware.LoggingMiddleware(http.RedirectHandler("/notes/", http.StatusFound)))
|
||||
router.Handle("/notes/", sessions.AsMiddleware(middleware.LoggingMiddleware(http.StripPrefix("/notes", notesRouter))))
|
||||
router.Handle("/auth/", sessions.AsMiddleware(middleware.LoggingMiddleware(http.StripPrefix("/auth", authRouter))))
|
||||
router.Handle(
|
||||
"/static/",
|
||||
middleware.LoggingMiddleware(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue