          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"))]

(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 cm]}]
   (let [params (merge {:grant_type "client_credentials"}
                       credentials)
         resp (client/post (get openid-config "token_endpoint")


(defn- lookup-user-id
  "Lookup email -> Keycloak user-id, via cached Keycloak API."
  [connection-manager req-opts api-root user-id-cache email]
  (if-some [user-id (get-user-id user-id-cache email)]
    user-id
    (let [url (format "%s/users/?email=%s" api-root email)]
      (let [users (-> (client/get url (assoc req-opts :connection-manager connection-manager)) :body json/decode)]
        (when-some [user-id (active-user users email)]
          (-> user-id-cache
              (swap! assoc email user-id)
