44 "crypto/rand"
55 "encoding/json"
66 "net/http"
7+ "slices"
8+ "strings"
79
810 "github.com/dexidp/dex/api/v2"
911 "github.com/hyprmcp/mcp-gateway/config"
@@ -21,9 +23,10 @@ type ClientInformation struct {
2123 ClientName string `json:"client_name,omitempty"`
2224 RedirectURIs []string `json:"redirect_uris"`
2325 LogoURI string `json:"logo_uri,omitempty"`
26+ Scope string `json:"scope,omitempty"`
2427}
2528
26- func NewDynamicClientRegistrationHandler (config * config.Config ) (http.Handler , error ) {
29+ func NewDynamicClientRegistrationHandler (config * config.Config , meta map [ string ] any ) (http.Handler , error ) {
2730 grpcClient , err := grpc .NewClient (
2831 config .DexGRPCClient .Addr ,
2932 grpc .WithTransportCredentials (insecure .NewCredentials ()),
@@ -61,13 +64,19 @@ func NewDynamicClientRegistrationHandler(config *config.Config) (http.Handler, e
6164 w .WriteHeader (http .StatusCreated )
6265 w .Header ().Set ("Content-Type" , "application/json" )
6366
64- err = json . NewEncoder ( w ). Encode ( ClientInformation {
67+ resp := ClientInformation {
6568 ClientID : clientResponse .Client .Id ,
6669 ClientSecret : clientResponse .Client .Secret ,
6770 ClientName : clientResponse .Client .Name ,
6871 RedirectURIs : clientResponse .Client .RedirectUris ,
6972 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 )
7180 if err != nil {
7281 log .Get (r .Context ()).Error (err , "Failed to encode response" )
7382 }
@@ -79,3 +88,18 @@ func NewDynamicClientRegistrationHandler(config *config.Config) (http.Handler, e
7988func genRandom () string {
8089 return rand .Text ()
8190}
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