|
6 | 6 | "net/http"
|
7 | 7 | "reflect"
|
8 | 8 |
|
| 9 | + "github.com/go-chi/chi/v5" |
| 10 | + "github.com/google/uuid" |
9 | 11 | "golang.org/x/oauth2"
|
10 | 12 |
|
11 | 13 | "github.com/coder/coder/v2/coderd/database"
|
@@ -194,9 +196,47 @@ func ExtractOAuth2ProviderApp(db database.Store) func(http.Handler) http.Handler
|
194 | 196 | return func(next http.Handler) http.Handler {
|
195 | 197 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
196 | 198 | ctx := r.Context()
|
197 |
| - appID, ok := ParseUUIDParam(rw, r, "app") |
198 |
| - if !ok { |
199 |
| - return |
| 199 | + |
| 200 | + // App can come from a URL param, query param, or form value. |
| 201 | + paramID := "app" |
| 202 | + var appID uuid.UUID |
| 203 | + if chi.URLParam(r, paramID) != "" { |
| 204 | + var ok bool |
| 205 | + appID, ok = ParseUUIDParam(rw, r, "app") |
| 206 | + if !ok { |
| 207 | + return |
| 208 | + } |
| 209 | + } else { |
| 210 | + // If not provided by the url, then it is provided according to the |
| 211 | + // oauth 2 spec. This can occur with query params, or in the body as form |
| 212 | + // parameters. |
| 213 | + // This also depends on if you are doing a POST (tokens) or GET (authorize). |
| 214 | + |
| 215 | + // This can also be sent as a query param for oauth exchanging. |
| 216 | + // According to the oauth2 spec. |
| 217 | + paramAppID := r.URL.Query().Get("client_id") |
| 218 | + if paramAppID == "" { |
| 219 | + // Check the form params! |
| 220 | + if r.ParseForm() == nil { |
| 221 | + paramAppID = r.Form.Get("client_id") |
| 222 | + } |
| 223 | + } |
| 224 | + if paramAppID == "" { |
| 225 | + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 226 | + Message: "Missing OAuth2 client ID.", |
| 227 | + }) |
| 228 | + return |
| 229 | + } |
| 230 | + |
| 231 | + var err error |
| 232 | + appID, err = uuid.Parse(paramAppID) |
| 233 | + if err != nil { |
| 234 | + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 235 | + Message: "Invalid OAuth2 client ID.", |
| 236 | + Detail: err.Error(), |
| 237 | + }) |
| 238 | + return |
| 239 | + } |
200 | 240 | }
|
201 | 241 |
|
202 | 242 | app, err := db.GetOAuth2ProviderAppByID(ctx, appID)
|
|
0 commit comments