4
4
"crypto/rand"
5
5
"encoding/json"
6
6
"net/http"
7
+ "slices"
8
+ "strings"
7
9
8
10
"github.com/dexidp/dex/api/v2"
9
11
"github.com/hyprmcp/mcp-gateway/config"
@@ -21,9 +23,10 @@ type ClientInformation struct {
21
23
ClientName string `json:"client_name,omitempty"`
22
24
RedirectURIs []string `json:"redirect_uris"`
23
25
LogoURI string `json:"logo_uri,omitempty"`
26
+ Scope string `json:"scope,omitempty"`
24
27
}
25
28
26
- func NewDynamicClientRegistrationHandler (config * config.Config ) (http.Handler , error ) {
29
+ func NewDynamicClientRegistrationHandler (config * config.Config , meta map [ string ] any ) (http.Handler , error ) {
27
30
grpcClient , err := grpc .NewClient (
28
31
config .DexGRPCClient .Addr ,
29
32
grpc .WithTransportCredentials (insecure .NewCredentials ()),
@@ -61,13 +64,19 @@ func NewDynamicClientRegistrationHandler(config *config.Config) (http.Handler, e
61
64
w .WriteHeader (http .StatusCreated )
62
65
w .Header ().Set ("Content-Type" , "application/json" )
63
66
64
- err = json . NewEncoder ( w ). Encode ( ClientInformation {
67
+ resp := ClientInformation {
65
68
ClientID : clientResponse .Client .Id ,
66
69
ClientSecret : clientResponse .Client .Secret ,
67
70
ClientName : clientResponse .Client .Name ,
68
71
RedirectURIs : clientResponse .Client .RedirectUris ,
69
72
LogoURI : clientResponse .Client .LogoUrl ,
70
- })
73
+ }
74
+
75
+ if scopesSupported := getSupportedScopes (meta ); len (scopesSupported ) > 0 {
76
+ resp .Scope = strings .Join (scopesSupported , " " )
77
+ }
78
+
79
+ err = json .NewEncoder (w ).Encode (resp )
71
80
if err != nil {
72
81
log .Get (r .Context ()).Error (err , "Failed to encode response" )
73
82
}
@@ -79,3 +88,18 @@ func NewDynamicClientRegistrationHandler(config *config.Config) (http.Handler, e
79
88
func genRandom () string {
80
89
return rand .Text ()
81
90
}
91
+
92
+ func getSupportedScopes (meta map [string ]any ) []string {
93
+ if scopesSupported , ok := meta ["scopes_supported" ].([]any ); ok {
94
+ scopesSupportedStr := make ([]string , 0 , len (scopesSupported ))
95
+ for _ , v := range scopesSupported {
96
+ if s , ok := v .(string ); ok {
97
+ scopesSupportedStr = append (scopesSupportedStr , s )
98
+ }
99
+ }
100
+
101
+ return slices .Clip (scopesSupportedStr )
102
+ }
103
+
104
+ return nil
105
+ }
0 commit comments