Skip to content

Commit 282db47

Browse files
authored
chore: add config for DCR public/private client (#36)
1 parent e6c7888 commit 282db47

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

config/config.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@ type Config struct {
1818
}
1919

2020
type Authorization struct {
21-
Server string `yaml:"server" json:"server"`
22-
ServerMetadataProxyEnabled bool `yaml:"serverMetadataProxyEnabled" json:"serverMetadataProxyEnabled"`
23-
AuthorizationProxyEnabled bool `yaml:"authorizationProxyEnabled" json:"authorizationProxyEnabled"`
24-
DynamicClientRegistrationEnabled bool `yaml:"dynamicClientRegistrationEnabled" json:"dynamicClientRegistrationEnabled"`
21+
Server string `yaml:"server" json:"server"`
22+
ServerMetadataProxyEnabled bool `yaml:"serverMetadataProxyEnabled" json:"serverMetadataProxyEnabled"`
23+
AuthorizationProxyEnabled bool `yaml:"authorizationProxyEnabled" json:"authorizationProxyEnabled"`
24+
// DynamicClientRegistrationEnabled
25+
//
26+
// Deprecated: use DynamicClientRegistration instead
27+
DynamicClientRegistrationEnabled *bool `yaml:"dynamicClientRegistrationEnabled" json:"dynamicClientRegistrationEnabled"`
28+
DynamicClientRegistration *DynamicClientRegistration `yaml:"dynamicClientRegistration" json:"dynamicClientRegistration"`
29+
}
30+
31+
func (c *Authorization) GetDynamicClientRegistration() DynamicClientRegistration {
32+
if c.DynamicClientRegistration != nil {
33+
return *c.DynamicClientRegistration
34+
} else if c.DynamicClientRegistrationEnabled != nil && *c.DynamicClientRegistrationEnabled {
35+
return DynamicClientRegistration{true, true}
36+
} else {
37+
return DynamicClientRegistration{false, false}
38+
}
39+
40+
}
41+
42+
type DynamicClientRegistration struct {
43+
Enabled bool `yaml:"enabled" json:"enabled"`
44+
PublicClient bool `yaml:"publicClient" json:"publicClient"`
2545
}
2646

2747
type DexGRPCClient struct {
@@ -122,7 +142,7 @@ func (c *Config) Validate() error {
122142
return fmt.Errorf("authorization server is required")
123143
}
124144

125-
if c.Authorization.DynamicClientRegistrationEnabled {
145+
if c.Authorization.GetDynamicClientRegistration().Enabled {
126146
if !c.Authorization.ServerMetadataProxyEnabled {
127147
return fmt.Errorf("serverMetadataProxyEnabled must be true when dynamicClientRegistrationEnabled is true")
128148
}

examples/who-am-i/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
required: true
4141

4242
who-am-i:
43-
image: ghcr.io/hyprmcp/mcp-who-am-i:0.1.1
43+
image: ghcr.io/hyprmcp/mcp-who-am-i:0.1.2
4444
ports:
4545
- 3000:3000
4646

oauth/authorization_server_metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewAuthorizationServerMetadataHandler(config *config.Config) http.Handler {
2222
http.Error(w, "Failed to retrieve authorization server metadata", http.StatusInternalServerError)
2323
}
2424

25-
if config.Authorization.DynamicClientRegistrationEnabled {
25+
if config.Authorization.GetDynamicClientRegistration().Enabled {
2626
if _, ok := metadata["registration_endpoint"]; !ok {
2727
registrationURI, _ := url.Parse(config.Host.String())
2828
registrationURI.Path = DynamicClientRegistrationPath

oauth/dynamic_client_registration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func NewDynamicClientRegistrationHandler(config *config.Config, meta map[string]
5454
Public: true,
5555
}
5656

57+
if !config.Authorization.GetDynamicClientRegistration().PublicClient {
58+
client.Secret = genRandom()
59+
}
60+
5761
clientResponse, err := dexClient.CreateClient(r.Context(), &api.CreateClientReq{Client: &client})
5862
if err != nil {
5963
log.Get(r.Context()).Error(err, "failed to create client")

oauth/oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (mgr *Manager) Register(mux *http.ServeMux) error {
6363
mux.Handle(AuthorizationServerMetadataPath, NewAuthorizationServerMetadataHandler(mgr.config))
6464
}
6565

66-
if mgr.config.Authorization.DynamicClientRegistrationEnabled {
66+
if mgr.config.Authorization.GetDynamicClientRegistration().Enabled {
6767
if handler, err := NewDynamicClientRegistrationHandler(mgr.config, mgr.authServerMeta); err != nil {
6868
return err
6969
} else {

0 commit comments

Comments
 (0)