          req-opts (-> req-opts
                       (select-keys [:timeout])
                       (assoc :form-params params))]
-     (if-some [access-token (-> (client/post url (assoc req-opts :connection-manager cm))
+     (if-some [access-token (-> (client/post url (assoc req-opts :connection-manager connection-manager))
                                 :body
                                 json/decode
                                 (get "access_token"))]

  (log/info "Starting keycloak")
  (let [{:keys [issuer openid-config api-root] :as this} (init-keycloak (assoc data :credentials credentials :max-user-ids-cache max-user-ids-cache))
        http-timeout 10000
        cm (http.conn-mgr/make-reusable-conn-manager {:timeout 2 :threads 3 :insecure? false :default-per-route 10})
        openid-config (fetch-openid-configuration issuer {:timeout http-timeout :connection-manager cm})]
    (log/info "Successfully got openid-config from provider.")
    (assoc this
           :cm cm
           :http-timeout http-timeout
           :openid-config openid-config)))

(defmethod ig/halt-key! :akvo.lumen.component.keycloak/keycloak  [_ opts]
  (log/info :keycloak "closing connection manager" (:cm opts))
  (http.conn-mgr/shutdown-manager (:cm opts)))


(s/def ::client_id string?)

(defn request-headers
  "Create a set of request headers to use for interaction with the Keycloak
   REST API. This allows us to reuse the same token for multiple requests."
  ([{:keys [openid-config credentials connection-manager]}]
   (let [params (merge {:grant_type "client_credentials"}
                       credentials)
         resp (client/post (get openid-config "token_endpoint")
