mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* chore: move `/gitauth` to `/externalauth` on the frontend This actually took a lot more jank than anticipated, so I wanted to split this up before adding the ability to embed new providers. * Rename FE * Fix em' up * Fix linting error * Fix e2e tests * chore: update helm golden files
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package httpmw
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/coder/coder/v2/coderd/externalauth"
|
|
"github.com/coder/coder/v2/coderd/httpapi"
|
|
)
|
|
|
|
type externalAuthParamContextKey struct{}
|
|
|
|
func ExternalAuthParam(r *http.Request) *externalauth.Config {
|
|
config, ok := r.Context().Value(externalAuthParamContextKey{}).(*externalauth.Config)
|
|
if !ok {
|
|
panic("developer error: external auth param middleware not provided")
|
|
}
|
|
return config
|
|
}
|
|
|
|
func ExtractExternalAuthParam(configs []*externalauth.Config) func(next http.Handler) http.Handler {
|
|
configByID := make(map[string]*externalauth.Config)
|
|
for _, c := range configs {
|
|
configByID[c.ID] = c
|
|
}
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
config, ok := configByID[chi.URLParam(r, "externalauth")]
|
|
if !ok {
|
|
httpapi.ResourceNotFound(w)
|
|
return
|
|
}
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), externalAuthParamContextKey{}, config))
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|