Skip to content

Commit

Permalink
feat(auth): add config opt to send port number in callback urls
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Aug 23, 2024
1 parent d0e4550 commit 9ed14d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ func RequireAuth(handlerFunc http.HandlerFunc, auth *AuthService) http.HandlerFu
}

func buildCallbackURL(provider string) string {
hostUrl := fmt.Sprintf("%s", config.Envs.PublicHost)
if config.Envs.SendPortInCallback {
hostUrl = fmt.Sprintf("%s:%s", hostUrl, config.Envs.Port)
}
return fmt.Sprintf(
"%s:%s/auth/%s/callback",
config.Envs.PublicHost,
config.Envs.Port,
"%s/auth/%s/callback",
hostUrl,
provider,
)
}
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
type Config struct {
PublicHost string
Port string
SendPortInCallback bool
DatabaseURL string
CookiesAuthSecret string
CookiesAuthAgeInSeconds int
Expand All @@ -37,6 +38,7 @@ func initConfig() *Config {
return &Config{
PublicHost: getEnv("PUBLIC_HOST", "http://localhost"),
Port: getEnv("PORT", "3000"),
SendPortInCallback: getEnvAsBool("SEND_PORT_IN_CALLBACK", true),
DatabaseURL: getEnv("DATABASE_URL", "file:mnemstart.db"),
CookiesAuthSecret: getEnv("COOKIES_AUTH_SECRET", "youllneverguesswhatthisis"),
CookiesAuthAgeInSeconds: getEnvAsInt("COOKIES_AUTH_AGE_IN_SECONDS", thirtyDaysInSeconds),
Expand Down

0 comments on commit 9ed14d9

Please sign in to comment.