@@ -2,16 +2,50 @@ package http
22
33import  (
44	"encoding/json" 
5+ 	"io" 
56	"net/http" 
67
78	"github.com/containers/kubernetes-mcp-server/pkg/config" 
89	"github.com/containers/kubernetes-mcp-server/pkg/mcp" 
910)
1011
1112const  (
12- 	oauthProtectedResourceEndpoint  =  "/.well-known/oauth-protected-resource" 
13+ 	oauthAuthorizationServerEndpoint  =  "/.well-known/oauth-authorization-server" 
14+ 	oauthProtectedResourceEndpoint    =  "/.well-known/oauth-protected-resource" 
1315)
1416
17+ func  OAuthAuthorizationServerHandler (staticConfig  * config.StaticConfig ) http.HandlerFunc  {
18+ 	return  func (w  http.ResponseWriter , r  * http.Request ) {
19+ 		if  staticConfig .AuthorizationURL  ==  ""  {
20+ 			http .Error (w , "Authorization URL is not configured" , http .StatusNotFound )
21+ 			return 
22+ 		}
23+ 		req , err  :=  http .NewRequest (r .Method , staticConfig .AuthorizationURL + oauthAuthorizationServerEndpoint , nil )
24+ 		if  err  !=  nil  {
25+ 			http .Error (w , "Failed to create request: " + err .Error (), http .StatusInternalServerError )
26+ 			return 
27+ 		}
28+ 		resp , err  :=  http .DefaultClient .Do (req .WithContext (r .Context ()))
29+ 		if  err  !=  nil  {
30+ 			http .Error (w , "Failed to perform request: " + err .Error (), http .StatusInternalServerError )
31+ 			return 
32+ 		}
33+ 		defer  func () { _  =  resp .Body .Close () }()
34+ 		body , err  :=  io .ReadAll (resp .Body )
35+ 		if  err  !=  nil  {
36+ 			http .Error (w , "Failed to read response body: " + err .Error (), http .StatusInternalServerError )
37+ 			return 
38+ 		}
39+ 		for  key , values  :=  range  resp .Header  {
40+ 			for  _ , value  :=  range  values  {
41+ 				w .Header ().Add (key , value )
42+ 			}
43+ 		}
44+ 		w .WriteHeader (resp .StatusCode )
45+ 		_ , _  =  w .Write (body )
46+ 	}
47+ }
48+ 
1549func  OAuthProtectedResourceHandler (mcpServer  * mcp.Server , staticConfig  * config.StaticConfig ) http.HandlerFunc  {
1650	return  func (w  http.ResponseWriter , r  * http.Request ) {
1751		w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments