MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / handleDynamicClientRegistration

Method handleDynamicClientRegistration

oauthex/oauthex_test.go:124–151  ·  view source on GitHub ↗

handleDynamicClientRegistration handles dynamic client registration requests, as defined in RFC 7591.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

122// handleDynamicClientRegistration handles dynamic client registration requests,
123// as defined in RFC 7591.
124func (s *state) handleDynamicClientRegistration(w http.ResponseWriter, r *http.Request) {
125 if r.Method != http.MethodPost {
126 http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
127 return
128 }
129
130 var crm ClientRegistrationMetadata
131 if err := json.NewDecoder(r.Body).Decode(&crm); err != nil {
132 http.Error(w, fmt.Sprintf("invalid JSON in request body: %v", err), http.StatusBadRequest)
133 return
134 }
135 clientID := fmt.Sprintf("fake-client-%d", time.Now().UnixNano())
136
137 response := ClientRegistrationResponse{
138 ClientRegistrationMetadata: crm,
139 ClientID: clientID,
140 ClientIDIssuedAt: time.Now(),
141 ClientSecret: "fake-registration-access-secret",
142 }
143 var buf bytes.Buffer
144 if err := json.NewEncoder(&buf).Encode(response); err != nil {
145 http.Error(w, err.Error(), http.StatusInternalServerError)
146 return
147 }
148 w.Header().Set("Content-Type", "application/json")
149 w.WriteHeader(http.StatusCreated)
150 w.Write(buf.Bytes())
151}
152
153func (s *state) handleToken(w http.ResponseWriter, r *http.Request) {
154 r.ParseForm()

Callers

nothing calls this directly

Calls 4

DecodeMethod · 0.80
BytesMethod · 0.80
WriteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected