handleDynamicClientRegistration handles dynamic client registration requests, as defined in RFC 7591.
(w http.ResponseWriter, r *http.Request)
| 122 | // handleDynamicClientRegistration handles dynamic client registration requests, |
| 123 | // as defined in RFC 7591. |
| 124 | func (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 | |
| 153 | func (s *state) handleToken(w http.ResponseWriter, r *http.Request) { |
| 154 | r.ParseForm() |