mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: move /gitauth
to /externalauth
on the frontend (#9954)
* 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
This commit is contained in:
40
coderd/httpmw/externalauthparam.go
Normal file
40
coderd/httpmw/externalauthparam.go
Normal file
@ -0,0 +1,40 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user