   [extension msg]
   (timbre/debugf "New message %s for extension %s" msg extension)
   (if-let [issue (get-in extension [:config :thread->issue (msg :thread-id)])]
-    (let [sender (db/with-conn (db/user-by-id (msg :user-id)))]
+    (let [sender (db/user-by-id (msg :user-id))]
       (fetch-asana-info
         (extension :id) :post (str "/tasks/" issue "/stories")
         {:form-params {"text" (format comment-format-str (sender :nickname)

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

(defn refresh-token

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