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

Commit 14a82d4

Browse files
committed
feat: add environment variables
1 parent a759e3e commit 14a82d4

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

.devcontainer/devcontainer.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PORT=3000
2+
REDIRECT_PATH=https://example.com
3+
REDIRECT_SESSION_PARAM_KEY=ory_kratos_session
4+
SESSION_COOKIE_KEY=ory_kratos_session

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
// "postCreateCommand": "go version",
2828

2929
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
30-
"remoteUser": "vscode"
30+
"remoteUser": "vscode",
31+
32+
// Load environment variables: https://code.visualstudio.com/remote/advancedcontainers/environment-variables#_option-2-use-an-env-file
33+
"runArgs": ["--env-file",".devcontainer/devcontainer.env"]
3134
}

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ RUN go mod verify
99
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/ory-kratos-session-catcher
1010

1111
FROM scratch
12+
ENV PORT=3000
13+
ENV REDIRECT_SESSION_PARAM_KEY=ory_kratos_session
14+
ENV SESSION_COOKIE_KEY=ory_kratos_session
1215
COPY --from=builder /go/bin/ory-kratos-session-catcher /go/bin/ory-kratos-session-catcher
13-
EXPOSE 3000
16+
EXPOSE $PORT
1417
ENTRYPOINT ["/go/bin/ory-kratos-session-catcher"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ory Kratos Session Catcher
22

3-
Unfortunately with [Ory Kratos](https://www.ory.sh/kratos/) it is currently impossible to offer authentication via one of the social login providers (Google, Apple, ..) for non-browser API apps like mobile apps. The browser API cannot be used, because the session is sent as a HttpOnly cookie to the client. It is hard or impossible to extract the session from a mobile webview.
3+
Unfortunately with [Ory Kratos](https://www.ory.sh/kratos/) alone it is currently impossible to offer authentication via one of the social login providers (Google, Apple, ..) for non-browser API apps like mobile apps. The browser API cannot be used, because the session is sent as a HttpOnly cookie to the client. It is hard or impossible to extract the session from a mobile webview.
44

55
This service can be called after a session is returned from Kratos to a browser endpoint. It will read the cookie and redirects the user back to a non-browser app via deep linking.
66

ory_kratos_session_catcher.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
6+
"os"
57

68
"github.com/gofiber/fiber/v2"
79
)
810

11+
type configuration struct {
12+
port string
13+
redirectPath string
14+
redirectSessionParamKey string
15+
sessionCookieKey string
16+
}
17+
18+
func (c *configuration) load() {
19+
c.port = os.Getenv("PORT")
20+
c.redirectPath = os.Getenv("REDIRECT_PATH")
21+
c.redirectSessionParamKey = os.Getenv("REDIRECT_SESSION_PARAM_KEY")
22+
c.sessionCookieKey = os.Getenv("SESSION_COOKIE_KEY")
23+
}
24+
25+
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)
27+
}
28+
929
func main() {
30+
c := &configuration{}
31+
c.load()
32+
c.display()
33+
1034
app := fiber.New(fiber.Config{
1135
AppName: "Ory Kratos Session Catcher",
1236
})
@@ -15,5 +39,5 @@ func main() {
1539
return c.SendString("Hello, World!")
1640
})
1741

18-
log.Fatal(app.Listen(":3000"))
42+
log.Fatal(app.Listen(fmt.Sprintf(":%s", c.port)))
1943
}

0 commit comments

Comments
 (0)