                                           "refresh_token" refresh-tok}})]
       (if (= 200 (:status resp))
         (let [{:strs [access_token refresh_token]} (json/read-str (:body resp))]
-          (db/with-conn
-            (db/save-extension-token! (ext :id)
-                                      {:access-token access_token
-                                       :refresh-token (or refresh_token
-                                                          refresh-tok)})))
+          (db/save-extension-token! (ext :id)
+                                    {:access-token access_token
+                                     :refresh-token (or refresh_token
+                                                        refresh-tok)}))
         (do (timbre/warnf "Bad response when exchanging token %s" (:body resp))
             nil)))))
 

        (fetch-asana-info extension-id :post "/webhooks"
                          {:form-params {"resource" resource-id
                                         "target" (str webhook-uri "/" extension-id)}})]
    (db/with-conn
      (db/set-extension-config! extension-id :webhook-id (data "id")))))

(defn unregister-webhook
  [extension-id webhook-id]

(defn create-asana-extension
  [{:keys [id group-id user-name tag-id]}]
  ; TODO: verify user name is valid
  (let [user-id (db/uuid)]
    ; TODO: need a reasonable way to create this extension-only user
    (db/create-user! {:id user-id
                      :email (random-nonce 50)
                      :password (random-nonce 50)
                      ; TODO: ability to set avatar/reasonable default avatar
                      :avatar "data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
                      :nickname user-name})
    (db/user-add-to-group! user-id group-id)
    (db/create-extension! {:id id
                           :group-id group-id
                           :type :asana
                           :user-id user-id
                           :config {:tag-id tag-id}})))

(declare unregister-webhook)

(defn destroy-asana-extension
  [id]
  (when-let [webhook-id (-> (db/extension-by-id id)
                            (get-in [:config :webhook-id]))]
    (unregister-webhook id webhook-id))
  (db/retract-extension! id))

;; Authentication flow
(def token-url "https://app.asana.com/-/oauth_token")
