Skip to content

Commit c941efa

Browse files
committed
fix cookies when self hosting on http
1 parent 1cd256b commit c941efa

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ api:
5050
# Make sure to add {public_url}/auth/callback to the OAuth2 Redirect URLs of your application in the Discord dev portal
5151
public_url: "http://localhost:5173/api"
5252

53+
# Make sure to enable this when you don't have an SSL (HTTPS) certificate
54+
insecure_cookies: true
55+
5356
host: "localhost"
5457
port: 8080
5558

@@ -138,6 +141,7 @@ services:
138141
- "8080:8080"
139142
environment:
140143
- EMBEDG_API__HOST=0.0.0.0
144+
- EMBEDG_API__INSECURE_COOKIES=true
141145
- EMBEDG_POSTGRES__HOST=postgres
142146
- EMBEDG_POSTGRES__USER=postgres
143147
- EMBEDG_POSTGRES__DB=embedg

docker-compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ services:
3636
- "8080:8080"
3737
environment:
3838
- EMBEDG_API__HOST=0.0.0.0
39+
- EMBEDG_API__INSECURE_COOKIES=true
3940
- EMBEDG_POSTGRES__HOST=postgres
4041
- EMBEDG_POSTGRES__USER=postgres
4142
- EMBEDG_POSTGRES__DB=embedg

embedg-server/api/handlers/auth/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func setOauthStateCookie(c *fiber.Ctx) string {
170170
Name: "oauth_state",
171171
Value: state,
172172
HTTPOnly: true,
173-
Secure: true,
173+
Secure: !viper.GetBool("api.insecure_cookies"),
174174
})
175175
return state
176176
}

embedg-server/api/session/session.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/gofiber/fiber/v2"
1313
"github.com/merlinfuchs/embed-generator/embedg-server/db/postgres"
1414
"github.com/rs/zerolog/log"
15+
"github.com/spf13/viper"
1516
)
1617

1718
type Session struct {
@@ -88,7 +89,7 @@ func (s *SessionManager) CreateSessionCookie(c *fiber.Ctx, token string) {
8889
Name: "session_token",
8990
Value: token,
9091
HTTPOnly: true,
91-
Secure: true,
92+
Secure: !viper.GetBool("api.insecure_cookies"),
9293
SameSite: "strict",
9394
Expires: time.Now().UTC().Add(30 * 24 * time.Hour),
9495
})

0 commit comments

Comments
 (0)