Skip to content

Commit f66ddf9

Browse files
committed
Add TINYAUTH_AUTH_STANDALONE option
Allows to use TinyAuth on top-level domain only, but forbids automatic cross-app authentication using Traefik or Nginx.
1 parent d71a8e0 commit f66ddf9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

internal/bootstrap/app_bootstrap.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ func (app *BootstrapApp) Setup() error {
9999
}
100100

101101
// Get cookie domain
102-
cookieDomain, err := utils.GetCookieDomain(app.context.appUrl)
102+
cookieDomainResolver := utils.GetCookieDomain
103+
if app.config.Auth.Standalone {
104+
tlog.App.Info().Msg("Standalone mode enabled, automatic authentication for proxied apps will not work")
105+
cookieDomainResolver = utils.GetStandaloneCookieDomain
106+
}
107+
108+
cookieDomain, err := cookieDomainResolver(app.context.appUrl)
103109

104110
if err != nil {
105111
return err

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type AuthConfig struct {
115115
IP IPConfig `description:"IP whitelisting config options." yaml:"ip"`
116116
Users []string `description:"Comma-separated list of users (username:hashed_password)." yaml:"users"`
117117
UsersFile string `description:"Path to the users file." yaml:"usersFile"`
118+
Standalone bool `description:"Run in standalone mode, do not set cookies for subdomains." yaml:"standalone"`
118119
SecureCookie bool `description:"Enable secure cookies." yaml:"secureCookie"`
119120
SessionExpiry int `description:"Session expiry time in seconds." yaml:"sessionExpiry"`
120121
SessionMaxLifetime int `description:"Maximum session lifetime in seconds." yaml:"sessionMaxLifetime"`

internal/utils/app_utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func GetCookieDomain(u string) (string, error) {
4343
return domain, nil
4444
}
4545

46+
func GetStandaloneCookieDomain(u string) (string, error) {
47+
parsed, err := url.Parse(u)
48+
if err != nil {
49+
return "", err
50+
}
51+
52+
return parsed.Hostname(), nil
53+
}
54+
4655
func ParseFileToLine(content string) string {
4756
lines := strings.Split(content, "\n")
4857
users := make([]string, 0)

0 commit comments

Comments
 (0)