Skip to content

Commit

Permalink
fix cookies when self hosting on http
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs committed Apr 11, 2024
1 parent 1cd256b commit c941efa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ api:
# Make sure to add {public_url}/auth/callback to the OAuth2 Redirect URLs of your application in the Discord dev portal
public_url: "http://localhost:5173/api"

# Make sure to enable this when you don't have an SSL (HTTPS) certificate
insecure_cookies: true

host: "localhost"
port: 8080

Expand Down Expand Up @@ -138,6 +141,7 @@ services:
- "8080:8080"
environment:
- EMBEDG_API__HOST=0.0.0.0
- EMBEDG_API__INSECURE_COOKIES=true
- EMBEDG_POSTGRES__HOST=postgres
- EMBEDG_POSTGRES__USER=postgres
- EMBEDG_POSTGRES__DB=embedg
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ services:
- "8080:8080"
environment:
- EMBEDG_API__HOST=0.0.0.0
- EMBEDG_API__INSECURE_COOKIES=true
- EMBEDG_POSTGRES__HOST=postgres
- EMBEDG_POSTGRES__USER=postgres
- EMBEDG_POSTGRES__DB=embedg
Expand Down
2 changes: 1 addition & 1 deletion embedg-server/api/handlers/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func setOauthStateCookie(c *fiber.Ctx) string {
Name: "oauth_state",
Value: state,
HTTPOnly: true,
Secure: true,
Secure: !viper.GetBool("api.insecure_cookies"),
})
return state
}
3 changes: 2 additions & 1 deletion embedg-server/api/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/merlinfuchs/embed-generator/embedg-server/db/postgres"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)

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

0 comments on commit c941efa

Please sign in to comment.