Skip to content

Commit

Permalink
allow not setting header in soft-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed May 12, 2023
1 parent 6d0898a commit 6a87b59
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Application Options:
--match-whitelist-or-domain Allow users that match *either* whitelist or domain (enabled by default in v3) [$MATCH_WHITELIST_OR_DOMAIN]
--url-path= Callback URL Path (default: /_oauth) [$URL_PATH]
--secret= Secret used for signing (required) [$SECRET]
--soft-auth-user= Username used in header if unauthorized with soft-auth action (default: -) [$SOFT_AUTH_USER]
--soft-auth-user= If set, username used in header if unauthorized with soft-auth action [$SOFT_AUTH_USER]
--user-id-path= Dot notation path of a UserID for use with whitelist and X-Forwarded-User (default: email) [$USER_ID_PATH]
--whitelist= Only allow given UserID, comma separated, can be set multiple times [$WHITELIST]
--port= Port to listen on (default: 4181) [$PORT]
Expand Down
2 changes: 1 addition & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Config struct {
MatchWhitelistOrDomain bool `long:"match-whitelist-or-domain" env:"MATCH_WHITELIST_OR_DOMAIN" description:"Allow users that match *either* whitelist or domain (enabled by default in v3)"`
Path string `long:"url-path" env:"URL_PATH" default:"/_oauth" description:"Callback URL Path"`
SecretString string `long:"secret" env:"SECRET" description:"Secret used for signing (required)" json:"-"`
SoftAuthUser string `long:"soft-auth-user" env:"SOFT_AUTH_USER" default:"-" description:"Username used in header if unauthorized with soft-auth action"`
SoftAuthUser string `long:"soft-auth-user" env:"SOFT_AUTH_USER" default:"" description:"If set, username used in header if unauthorized with soft-auth action"`
UserPath string `long:"user-id-path" env:"USER_ID_PATH" default:"email" description:"Dot notation path of a UserID for use with whitelist and X-Forwarded-User"`
Whitelist CommaSeparatedList `long:"whitelist" env:"WHITELIST" env-delim:"," description:"Only allow given UserID, comma separated, can be set multiple times"`
Port int `long:"port" env:"PORT" default:"4181" description:"Port to listen on"`
Expand Down
2 changes: 1 addition & 1 deletion internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestConfigDefaults(t *testing.T) {
assert.Equal(time.Second*time.Duration(43200), c.Lifetime)
assert.False(c.MatchWhitelistOrDomain)
assert.Equal("/_oauth", c.Path)
assert.Equal("-", c.SoftAuthUser)
assert.Equal("", c.SoftAuthUser)
assert.Len(c.Whitelist, 0)
assert.Equal(c.Port, 4181)

Expand Down
4 changes: 3 additions & 1 deletion internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (s *Server) authHandler(providerName, rule string, soft bool) http.HandlerF
var unauthorized func(w http.ResponseWriter)
if soft {
unauthorized = func(w http.ResponseWriter) {
w.Header().Set(config.HeaderName, config.SoftAuthUser)
if config.SoftAuthUser != "" {
w.Header().Set(config.HeaderName, config.SoftAuthUser)
}
w.WriteHeader(200)
}
} else {
Expand Down

0 comments on commit 6a87b59

Please sign in to comment.