| 21 | } |
| 22 | |
| 23 | func ExtractExternalAuthParam(configs []*externalauth.Config) func(next http.Handler) http.Handler { |
| 24 | configByID := make(map[string]*externalauth.Config) |
| 25 | for _, c := range configs { |
| 26 | configByID[c.ID] = c |
| 27 | } |
| 28 | return func(next http.Handler) http.Handler { |
| 29 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 30 | config, ok := configByID[chi.URLParam(r, "externalauth")] |
| 31 | if !ok { |
| 32 | httpapi.ResourceNotFound(w) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | r = r.WithContext(context.WithValue(r.Context(), externalAuthParamContextKey{}, config)) |
| 37 | next.ServeHTTP(w, r) |
| 38 | }) |
| 39 | } |
| 40 | } |