Skip to content

Commit

Permalink
Add dev mode to the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Oct 15, 2024
1 parent 11c53ac commit a75d7d5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions example/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
RedirectURIs []string
UsersFile string
Issuer string
DevMode bool
}

// FromEnvVars loads configuration parameters from environment variables.
Expand All @@ -28,6 +29,7 @@ func FromEnvVars(defaults *Config) *Config {
RedirectURIs: defaults.RedirectURIs,
UsersFile: defaults.UsersFile,
Issuer: defaults.Issuer,
DevMode: defaults.DevMode,
}
if value, ok := os.LookupEnv("PORT"); ok {
cfg.Port = value
Expand All @@ -41,5 +43,8 @@ func FromEnvVars(defaults *Config) *Config {
if value, ok := os.LookupEnv("ISSUER"); ok {
cfg.Issuer = value
}
if value, ok := os.LookupEnv("DEV_MODE"); ok {
cfg.DevMode = value == "true"
}
return cfg
}
7 changes: 6 additions & 1 deletion example/server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ func TestFromEnvVars(t *testing.T) {
UsersFile: "/default/user/path",
RedirectURIs: []string{"re", "direct", "uris"},
Issuer: "123",
DevMode: true,
},
want: &Config{
Port: "6666",
UsersFile: "/default/user/path",
RedirectURIs: []string{"re", "direct", "uris"},
Issuer: "123",
DevMode: true,
},
},
{
Expand All @@ -42,18 +44,21 @@ func TestFromEnvVars(t *testing.T) {
"USERS_FILE": "/path/to/users",
"REDIRECT_URIS": "http://redirect/redirect",
"ISSUER": "someissuer",
"DEV_MODE": "true",
},
defaults: &Config{
Port: "6666",
UsersFile: "/default/user/path",
RedirectURIs: []string{"re", "direct", "uris"},
Issuer: "someissuer",
DevMode: false,
},
want: &Config{
Port: "1234",
UsersFile: "/path/to/users",
RedirectURIs: []string{"http://redirect/redirect"},
Issuer: "someissuer",
DevMode: true,
},
},
{
Expand All @@ -75,7 +80,7 @@ func TestFromEnvVars(t *testing.T) {
}
cfg := FromEnvVars(tc.defaults)
if fmt.Sprint(cfg) != fmt.Sprint(tc.want) {
t.Errorf("Expected FromEnvVars()=%q, but got %q", tc.want, cfg)
t.Errorf("Expected FromEnvVars()=%v, but got %v", tc.want, cfg)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion example/server/dynamic/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (

func init() {
storage.RegisterClients(
storage.NativeClient("native"),
storage.NativeClient("native", false),
storage.WebClient("web", "secret"),
storage.WebClient("api", "secret"),
)
Expand Down
2 changes: 1 addition & 1 deletion example/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
)

storage.RegisterClients(
storage.NativeClient("native", cfg.RedirectURIs...),
storage.NativeClient("native", cfg.DevMode, cfg.RedirectURIs...),
storage.WebClient("web", "secret"),
storage.WebClient("api", "secret"),
)
Expand Down
4 changes: 2 additions & 2 deletions example/server/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func RegisterClients(registerClients ...*Client) {
// - http://localhost without port specification (e.g. http://localhost/auth/callback)
// - custom protocol (e.g. custom://auth/callback)
// (the examples will be used as default, if none is provided)
func NativeClient(id string, redirectURIs ...string) *Client {
func NativeClient(id string, devMode bool, redirectURIs ...string) *Client {
if len(redirectURIs) == 0 {
redirectURIs = []string{
"http://localhost/auth/callback",
Expand All @@ -161,7 +161,7 @@ func NativeClient(id string, redirectURIs ...string) *Client {
responseTypes: []oidc.ResponseType{oidc.ResponseTypeCode},
grantTypes: []oidc.GrantType{oidc.GrantTypeCode, oidc.GrantTypeRefreshToken},
accessTokenType: op.AccessTokenTypeBearer,
devMode: false,
devMode: devMode,
idTokenUserinfoClaimsAssertion: false,
clockSkew: 0,
}
Expand Down

0 comments on commit a75d7d5

Please sign in to comment.