Skip to content
This repository was archived by the owner on Mar 3, 2024. It is now read-only.

Commit 90ccfec

Browse files
committed
feat: redirect if cookie set
1 parent 79bb7ae commit 90ccfec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ory_kratos_session_catcher.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ func (c *configuration) load() {
2323
}
2424

2525
func (c *configuration) display() {
26-
fmt.Println("Configuration:\n##############", "\nPORT: ", c.port, "\nREDIRECT_PATH: ", c.redirectPath, "\nREDIRECT_SESSION_PARAM_KEY: ", c.redirectSessionParamKey, "\nSESSION_COOKIE_KEY: ", c.sessionCookieKey)
26+
fmt.Println(
27+
"Configuration:\n##############",
28+
"\nPORT: ", c.port,
29+
"\nREDIRECT_PATH: ", c.redirectPath,
30+
"\nREDIRECT_SESSION_PARAM_KEY: ", c.redirectSessionParamKey,
31+
"\nSESSION_COOKIE_KEY: ", c.sessionCookieKey,
32+
)
2733
}
2834

2935
func main() {
@@ -35,8 +41,12 @@ func main() {
3541
AppName: "Ory Kratos Session Catcher",
3642
})
3743

38-
app.Get("/", func(c *fiber.Ctx) error {
39-
return c.SendString("Hello, World!")
44+
app.Get("/", func(ctx *fiber.Ctx) error {
45+
var sessionToken string = ctx.Cookies(c.sessionCookieKey)
46+
if sessionToken == "" {
47+
return ctx.SendStatus(400)
48+
}
49+
return ctx.Redirect(fmt.Sprintf("%s?%s=%s", c.redirectPath, c.redirectSessionParamKey, sessionToken))
4050
})
4151

4252
log.Fatal(app.Listen(fmt.Sprintf(":%s", c.port)))

0 commit comments

Comments
 (0)