Add same-port support for Dev OAuth provider to fix SameSite cookie issues
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 97
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 2
Description
Problem
The dev OAuth provider runs on a separate port (default 8084) from the main application. Since Chrome 80 (February 2020), browsers treat cookies without explicit SameSite attribute as SameSite=Lax by default. This breaks the dev OAuth flow because:
- User visits
127.0.0.1:8080/auth/dev/login- JWT handshake cookie is set on port 8080 - Browser redirects to
127.0.0.1:8084/login/oauth/authorize(dev OAuth server) - Dev OAuth redirects back to
127.0.0.1:8080/auth/dev/callback - Cookie is NOT sent because browsers treat different ports as different origins for SameSite purposes
Error: failed to get token - token cookie was not presented: http: named cookie not present
Why this happens
- Before 2020: Browsers sent cookies without SameSite restrictions
- After Chrome 80: Cookies default to
SameSite=Lax, blocking cross-origin redirects - Different ports (8080 vs 8084) = different origins from browser's cookie perspective
- Setting
SameSite=NonerequiresSecure=truewhich requires HTTPS (not practical for local dev) - Setting
SameSite=Laxordefaultdoesn't help because modern browsers enforce Lax by default
Proposed Solution
Add an option to run the dev OAuth handler on the same port as the main application using path-based routing instead of port-based separation.
API Changes
- Add
OAuthBasePathfield toParams:
type Params struct {
// ... existing fields
OAuthBasePath string // e.g., "/auth/dev/oauth" for same-port mode
}
- Add
Handler()method toDevAuthServer:
// Handler returns http.Handler for mounting on external router
func (d *DevAuthServer) Handler() http.Handler
- Add
DevAuthHandler()toService:
// DevAuthHandler returns handler for same-port mounting
func (s *Service) DevAuthHandler() (http.Handler, error)
Usage (same-port mode)
// Configure with OAuthBasePath
authenticator.AddDevProvider("", 0, "/auth/dev/oauth")
// Get handler and mount on main router
devHandler, _ := authenticator.DevAuthHandler()
router.Mount("/auth/dev/oauth", devHandler)
Backward Compatibility
- Default behavior unchanged (separate port 8084)
- Same-port mode is opt-in via
OAuthBasePath - No breaking changes
References
- Chromium SameSite Updates
- SameSite cookies explained
- Related issue in remark42: dev login broken with modern browsers
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Params, DevAuthServer.Handler, Service.DevAuthHandler, and AddDevProvider. Trace how the existing separate-port handler is created and how the main router mounts handlers. Done means OAuthBasePath enables same-port mounting while the default separate-port behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, authentication
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100