Hi @Scaramacci,

If you are starting out, it's always best to keep things as bare as 
possible until you discover a better way.

If as you say you can save the usr/pwd, and the decision to keep or replace 
the token is entirely left to the token provider, then I think something 
like the following below, may be suitable.

For anyone interested in learning the ins and outs of OO vs Functional, 
static typing vs. dynamic, I highly recommend the Programming Languages 
Specialization on Coursera.

(defonce user-tokens (atom {:users {}))

(defn get-updated-token [usr pwd tok]
     ;; Returns tok if still valid or a new token if expired/expiring. 
)

(defn get-token [usr, psw]
  (let [f (fn f [tok]
              [tok, (fn [] (f (get-updated-token usr psw tok)))])]
    (let [path [:users usr] 
          [_ thunk] (or (get-in @user-tokens path) (f nil))]
      (first (swap! user-tokens assoc-in path (thunk)))))) 

(defn geturl [url] 
  (client/get url {:oauth-token (get-token "user" "pwd")}))


On Tuesday, May 12, 2020 at 3:27:01 AM UTC-4, Scaramaccai wrote:
>
>
> (defn gettkn [usr, psw, tkn] (return a new token if tkn is expiring or tkn if 
> not expiring))
>
> (def wrap-gettkn (partial gettkn "myuser" "mypass"))
>
>
> (defn geturl [url, tkn] client/get url {:oauth-token (wrap-gettkn tkn)})
>
>
>
> I can "save" usr and psw, but I always have to "keep" the tkn around at 
> every level;
> while I would like the token to be "hidden" to the "geturl" clients (just 
> like I did in the "private token" in the pseudo-Java).
>
> What's the proper way of doing something like this in Clojure?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/d17770bc-7d66-4e87-9e66-0a900b745080%40googlegroups.com.

Reply via email to