This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-30
Channels
- # announcements (4)
- # babashka (8)
- # beginners (124)
- # calva (13)
- # cider (10)
- # circleci (6)
- # clj-kondo (193)
- # cljdoc (1)
- # cljs-dev (4)
- # clojure (50)
- # clojure-europe (28)
- # clojure-serbia (1)
- # clojure-spec (22)
- # clojure-uk (30)
- # clojurescript (11)
- # clojureverse-ops (3)
- # community-development (1)
- # conjure (5)
- # cursive (1)
- # datomic (11)
- # depstar (1)
- # events (2)
- # fulcro (7)
- # graalvm (2)
- # graphql (10)
- # helix (43)
- # hyperfiddle (14)
- # introduce-yourself (6)
- # jobs (2)
- # jobs-discuss (14)
- # kaocha (4)
- # luminus (2)
- # malli (24)
- # meander (6)
- # off-topic (4)
- # pathom (1)
- # polylith (13)
- # re-frame (6)
- # releases (1)
- # remote-jobs (1)
- # sci (14)
- # shadow-cljs (209)
- # tools-deps (30)
- # xtdb (26)
So i get an access token from Auth0 using .getTokenSilently()
, This returns a promise.
How can I get this token from within fulcro-http-remote
request middleware so I can add it to my headers?
I don’t want to store the token because Auth0 manages refreshing it with webworkers. If I store it i need to make a webworker to refresh it periodically which is what I’m trying to avoid.
See https://chrisodonnell.dev/posts/giftlist/api_auth/ for one solution
A simpler solution might be to override the Xhrio object.
(defn make-xhrio []
(let [xhrio (XhrIo.)
xhrio-send (.-send xhrio)]
(o/oset! xhrio "send"
(fn [url verb body headers]
(auth-http/get-token-silently-callback app
(fn [token]
(let [headers (o/oset! headers :!Authorization token)]
(.apply xhrio-send xhrio (clj->js [url verb body headers])))))))
xhrio))
This works
Yeah like that.