mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* feat: add github device flow for authentication This will allow us to add a GitHub OAuth provider out-of-the-box to reduce setup requirements. * Improve askpass view * Add routes to improve clarity of git auth * Redesign the git auth page * Refactor to add a page view * Fix sideways layout * Remove legacy notify * Fix git auth redirects * Add E2E tests * Fix route documentation * Fix imports * Remove unused imports * Fix E2E web test * Fix friendly message appearance * Fix layout shifting for full-screen sign-in * Fix height going to 100% * Fix comments
41 lines
980 B
Go
41 lines
980 B
Go
package httpmw
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/coder/coder/coderd/gitauth"
|
|
"github.com/coder/coder/coderd/httpapi"
|
|
)
|
|
|
|
type gitAuthParamContextKey struct{}
|
|
|
|
func GitAuthParam(r *http.Request) *gitauth.Config {
|
|
config, ok := r.Context().Value(gitAuthParamContextKey{}).(*gitauth.Config)
|
|
if !ok {
|
|
panic("developer error: gitauth param middleware not provided")
|
|
}
|
|
return config
|
|
}
|
|
|
|
func ExtractGitAuthParam(configs []*gitauth.Config) func(next http.Handler) http.Handler {
|
|
configByID := make(map[string]*gitauth.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, "gitauth")]
|
|
if !ok {
|
|
httpapi.ResourceNotFound(w)
|
|
return
|
|
}
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), gitAuthParamContextKey{}, config))
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|