Skip to content

Commit 8a6954e

Browse files
authored
changes for MCP auth (#1)
* have a registration endpoint
1 parent fbe08b3 commit 8a6954e

2 files changed

Lines changed: 49 additions & 43 deletions

File tree

server/handlers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type discoveryOIDC struct {
7979
UserInfo string `json:"userinfo_endpoint"`
8080
DeviceEndpoint string `json:"device_authorization_endpoint"`
8181
Introspect string `json:"introspection_endpoint"`
82+
Registration string `json:"registration_endpoint,omitempty"`
8283
GrantTypes []string `json:"grant_types_supported"`
8384
ResponseTypes []string `json:"response_types_supported"`
8485
Subjects []string `json:"subject_types_supported"`
@@ -96,6 +97,7 @@ type discoveryOAuth2 struct {
9697
Keys string `json:"jwks_uri"`
9798
DeviceEndpoint string `json:"device_authorization_endpoint,omitempty"`
9899
Introspect string `json:"introspection_endpoint,omitempty"`
100+
Registration string `json:"registration_endpoint,omitempty"`
99101
GrantTypes []string `json:"grant_types_supported"`
100102
ResponseTypes []string `json:"response_types_supported"`
101103
CodeChallengeAlgs []string `json:"code_challenge_methods_supported,omitempty"`
@@ -116,7 +118,7 @@ func (s *Server) discoveryHandler(ctx context.Context, t DiscoveryType) (http.Ha
116118
switch t {
117119
case DiscoveryOAuth2:
118120
d = s.constructDiscoveryOAuth2()
119-
default:
121+
case DiscoveryOIDC:
120122
d = s.constructDiscoveryOIDC(ctx)
121123
}
122124

@@ -141,6 +143,7 @@ func (s *Server) constructDiscoveryOIDC(ctx context.Context) discoveryOIDC {
141143
UserInfo: s.absURL("/userinfo"),
142144
DeviceEndpoint: s.absURL("/device/code"),
143145
Introspect: s.absURL("/token/introspect"),
146+
Registration: s.absURL("/register"),
144147
Subjects: []string{"public"},
145148
IDTokenAlgs: []string{string(jose.RS256)},
146149
CodeChallengeAlgs: []string{codeChallengeMethodS256, codeChallengeMethodPlain},
@@ -177,6 +180,7 @@ func (s *Server) constructDiscoveryOAuth2() discoveryOAuth2 {
177180
Keys: s.absURL("/keys"),
178181
DeviceEndpoint: s.absURL("/device/code"),
179182
Introspect: s.absURL("/token/introspect"),
183+
Registration: s.absURL("/register"),
180184
CodeChallengeAlgs: []string{codeChallengeMethodS256, codeChallengeMethodPlain},
181185
Scopes: []string{"offline_access"},
182186
AuthMethods: []string{"client_secret_basic", "client_secret_post"},

server/handlers_test.go

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestHandleDiscoveryOIDC(t *testing.T) {
6060
UserInfo: fmt.Sprintf("%s/userinfo", httpServer.URL),
6161
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
6262
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
63+
Registration: fmt.Sprintf("%s/register", httpServer.URL),
6364
GrantTypes: []string{
6465
"authorization_code",
6566
"refresh_token",
@@ -107,48 +108,49 @@ func TestHandleDiscoveryOIDC(t *testing.T) {
107108
}
108109

109110
func TestHandleDiscoveryOAuth2(t *testing.T) {
110-
httpServer, server := newTestServer(t, nil)
111-
defer httpServer.Close()
112-
113-
rr := httptest.NewRecorder()
114-
server.ServeHTTP(rr, httptest.NewRequest("GET", "/.well-known/oauth-authorization-server", nil))
115-
116-
if rr.Code != http.StatusOK {
117-
t.Errorf("expected 200 got %d", rr.Code)
118-
}
119-
120-
var res discoveryOAuth2
121-
err := json.NewDecoder(rr.Result().Body).Decode(&res)
122-
require.NoError(t, err)
123-
124-
require.Equal(t, discoveryOAuth2{
125-
Issuer: httpServer.URL,
126-
Auth: fmt.Sprintf("%s/auth", httpServer.URL),
127-
Token: fmt.Sprintf("%s/token", httpServer.URL),
128-
Keys: fmt.Sprintf("%s/keys", httpServer.URL),
129-
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
130-
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
131-
GrantTypes: []string{
132-
"authorization_code",
133-
"refresh_token",
134-
"urn:ietf:params:oauth:grant-type:device_code",
135-
"urn:ietf:params:oauth:grant-type:token-exchange",
136-
},
137-
ResponseTypes: []string{
138-
"code",
139-
},
140-
CodeChallengeAlgs: []string{
141-
"S256",
142-
"plain",
143-
},
144-
Scopes: []string{
145-
"offline_access",
146-
},
147-
AuthMethods: []string{
148-
"client_secret_basic",
149-
"client_secret_post",
150-
},
151-
}, res)
111+
httpServer, server := newTestServer(t, nil)
112+
defer httpServer.Close()
113+
114+
rr := httptest.NewRecorder()
115+
server.ServeHTTP(rr, httptest.NewRequest("GET", "/.well-known/oauth-authorization-server", nil))
116+
117+
if rr.Code != http.StatusOK {
118+
t.Errorf("expected 200 got %d", rr.Code)
119+
}
120+
121+
var res discoveryOAuth2
122+
err := json.NewDecoder(rr.Result().Body).Decode(&res)
123+
require.NoError(t, err)
124+
125+
require.Equal(t, discoveryOAuth2{
126+
Issuer: httpServer.URL,
127+
Auth: fmt.Sprintf("%s/auth", httpServer.URL),
128+
Token: fmt.Sprintf("%s/token", httpServer.URL),
129+
Keys: fmt.Sprintf("%s/keys", httpServer.URL),
130+
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
131+
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
132+
Registration: fmt.Sprintf("%s/register", httpServer.URL),
133+
GrantTypes: []string{
134+
"authorization_code",
135+
"refresh_token",
136+
"urn:ietf:params:oauth:grant-type:device_code",
137+
"urn:ietf:params:oauth:grant-type:token-exchange",
138+
},
139+
ResponseTypes: []string{
140+
"code",
141+
},
142+
CodeChallengeAlgs: []string{
143+
"S256",
144+
"plain",
145+
},
146+
Scopes: []string{
147+
"offline_access",
148+
},
149+
AuthMethods: []string{
150+
"client_secret_basic",
151+
"client_secret_post",
152+
},
153+
}, res)
152154
}
153155

154156
func TestHandleHealthFailure(t *testing.T) {

0 commit comments

Comments
 (0)