Skip to content

Commit a75d7d5

Browse files
author
Andrey Rusakov
committed
Add dev mode to the configuration
1 parent 11c53ac commit a75d7d5

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

example/server/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Config struct {
1515
RedirectURIs []string
1616
UsersFile string
1717
Issuer string
18+
DevMode bool
1819
}
1920

2021
// FromEnvVars loads configuration parameters from environment variables.
@@ -28,6 +29,7 @@ func FromEnvVars(defaults *Config) *Config {
2829
RedirectURIs: defaults.RedirectURIs,
2930
UsersFile: defaults.UsersFile,
3031
Issuer: defaults.Issuer,
32+
DevMode: defaults.DevMode,
3133
}
3234
if value, ok := os.LookupEnv("PORT"); ok {
3335
cfg.Port = value
@@ -41,5 +43,8 @@ func FromEnvVars(defaults *Config) *Config {
4143
if value, ok := os.LookupEnv("ISSUER"); ok {
4244
cfg.Issuer = value
4345
}
46+
if value, ok := os.LookupEnv("DEV_MODE"); ok {
47+
cfg.DevMode = value == "true"
48+
}
4449
return cfg
4550
}

example/server/config/config_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ func TestFromEnvVars(t *testing.T) {
2727
UsersFile: "/default/user/path",
2828
RedirectURIs: []string{"re", "direct", "uris"},
2929
Issuer: "123",
30+
DevMode: true,
3031
},
3132
want: &Config{
3233
Port: "6666",
3334
UsersFile: "/default/user/path",
3435
RedirectURIs: []string{"re", "direct", "uris"},
3536
Issuer: "123",
37+
DevMode: true,
3638
},
3739
},
3840
{
@@ -42,18 +44,21 @@ func TestFromEnvVars(t *testing.T) {
4244
"USERS_FILE": "/path/to/users",
4345
"REDIRECT_URIS": "http://redirect/redirect",
4446
"ISSUER": "someissuer",
47+
"DEV_MODE": "true",
4548
},
4649
defaults: &Config{
4750
Port: "6666",
4851
UsersFile: "/default/user/path",
4952
RedirectURIs: []string{"re", "direct", "uris"},
5053
Issuer: "someissuer",
54+
DevMode: false,
5155
},
5256
want: &Config{
5357
Port: "1234",
5458
UsersFile: "/path/to/users",
5559
RedirectURIs: []string{"http://redirect/redirect"},
5660
Issuer: "someissuer",
61+
DevMode: true,
5762
},
5863
},
5964
{
@@ -75,7 +80,7 @@ func TestFromEnvVars(t *testing.T) {
7580
}
7681
cfg := FromEnvVars(tc.defaults)
7782
if fmt.Sprint(cfg) != fmt.Sprint(tc.want) {
78-
t.Errorf("Expected FromEnvVars()=%q, but got %q", tc.want, cfg)
83+
t.Errorf("Expected FromEnvVars()=%v, but got %v", tc.want, cfg)
7984
}
8085
})
8186
}

example/server/dynamic/op.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828

2929
func init() {
3030
storage.RegisterClients(
31-
storage.NativeClient("native"),
31+
storage.NativeClient("native", false),
3232
storage.WebClient("web", "secret"),
3333
storage.WebClient("api", "secret"),
3434
)

example/server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
)
2929

3030
storage.RegisterClients(
31-
storage.NativeClient("native", cfg.RedirectURIs...),
31+
storage.NativeClient("native", cfg.DevMode, cfg.RedirectURIs...),
3232
storage.WebClient("web", "secret"),
3333
storage.WebClient("api", "secret"),
3434
)

example/server/storage/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func RegisterClients(registerClients ...*Client) {
144144
// - http://localhost without port specification (e.g. http://localhost/auth/callback)
145145
// - custom protocol (e.g. custom://auth/callback)
146146
// (the examples will be used as default, if none is provided)
147-
func NativeClient(id string, redirectURIs ...string) *Client {
147+
func NativeClient(id string, devMode bool, redirectURIs ...string) *Client {
148148
if len(redirectURIs) == 0 {
149149
redirectURIs = []string{
150150
"http://localhost/auth/callback",
@@ -161,7 +161,7 @@ func NativeClient(id string, redirectURIs ...string) *Client {
161161
responseTypes: []oidc.ResponseType{oidc.ResponseTypeCode},
162162
grantTypes: []oidc.GrantType{oidc.GrantTypeCode, oidc.GrantTypeRefreshToken},
163163
accessTokenType: op.AccessTokenTypeBearer,
164-
devMode: false,
164+
devMode: devMode,
165165
idTokenUserinfoClaimsAssertion: false,
166166
clockSkew: 0,
167167
}

0 commit comments

Comments
 (0)