mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-26 13:27:57 +08:00
* Add endpoint to invalidate HTTP-Only cookie from the backend * Add methods to the UserClient SDK for logout * Remove session token fetch and add unit test for logout * Update public router to use JWT middleware * Add logout button to frontend. Route back to login page once logout is successful. * Add a logout failur event * Update logout logic in SDK * Remove unneeded endpoint from main.go * Update logoutlink reference * Fix request path; undo change in package order * Update common.css to incldue hanko-logout * feat(fronend-sdk): remove cookie during cross-domain operations * fix(frontend-sdk): No unauthorized error during logout, when the user is already logged out * feat(backend): Create an audit log entry when the user logs off * chore(frontend-sdk): re-generate jsdoc * fix: Adjust logout response codes and the corresponding frontend sdk error handling * chore(frontend-sdk): re-generate jsdoc * feat: add logout endpoint specification to the docs * Fix broken unit test * Remove logout button from elements * Add event listener on frontend to call the logout method from SDK * Rollback changes to SecuredContent on e2e tests * Update logout test on user * Update quickstart/public/assets/css/common.css Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com> --------- Co-authored-by: Björn Müller <bjoern.mueller@hanko.io> Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com>
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
mw "github.com/labstack/echo/v4/middleware"
|
|
"github.com/teamhanko/hanko/quickstart/middleware"
|
|
"html/template"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
t := &Template{
|
|
templates: template.Must(template.ParseGlob("public/html/*.html")),
|
|
}
|
|
|
|
hankoUrl := getEnv("HANKO_URL")
|
|
hankoElementUrl := getEnv("HANKO_ELEMENT_URL")
|
|
hankoFrontendSdkUrl := getEnv("HANKO_FRONTEND_SDK_URL")
|
|
hankoUrlInternal := hankoUrl
|
|
if value, ok := os.LookupEnv("HANKO_URL_INTERNAL"); ok {
|
|
hankoUrlInternal = value
|
|
}
|
|
|
|
e := echo.New()
|
|
e.Renderer = t
|
|
|
|
e.Use(mw.LoggerWithConfig(mw.LoggerConfig{
|
|
Format: `{"time":"${time_rfc3339_nano}","time_unix":"${time_unix}","id":"${id}","remote_ip":"${remote_ip}",` +
|
|
`"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` +
|
|
`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
|
|
`,"bytes_in":${bytes_in},"bytes_out":${bytes_out},"referer":"${referer}"}` + "\n",
|
|
}))
|
|
|
|
e.Use(middleware.CacheControlMiddleware())
|
|
|
|
e.Static("/static", "public/assets")
|
|
|
|
e.GET("/", func(c echo.Context) error {
|
|
indexData := IndexData{
|
|
HankoUrl: hankoUrl,
|
|
HankoElementUrl: hankoElementUrl,
|
|
}
|
|
return c.Render(http.StatusOK, "index.html", &indexData)
|
|
})
|
|
|
|
e.File("/unauthorized", "public/html/unauthorized.html")
|
|
e.File("/error", "public/html/error.html")
|
|
|
|
e.GET("/secured", func(c echo.Context) error {
|
|
return c.Render(http.StatusOK, "secured.html", map[string]interface{}{
|
|
"HankoFrontendSdkUrl": hankoFrontendSdkUrl,
|
|
"HankoUrl": hankoUrl,
|
|
"HankoElementUrl": hankoElementUrl,
|
|
})
|
|
}, middleware.SessionMiddleware(hankoUrlInternal))
|
|
|
|
if err := e.Start(":8080"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
type IndexData struct {
|
|
HankoUrl string
|
|
HankoElementUrl string
|
|
}
|
|
|
|
type Template struct {
|
|
templates *template.Template
|
|
}
|
|
|
|
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
return t.templates.ExecuteTemplate(w, name, data)
|
|
}
|
|
|
|
func getEnv(key string) string {
|
|
if value, ok := os.LookupEnv(key); ok {
|
|
return value
|
|
}
|
|
log.Fatalf("env key not set: %v", key)
|
|
return ""
|
|
}
|