Where to create OAuth users with cemerick / friend in Clojure
I finally got OAuth workflows working for Twitter and Facebook login to my Clojure Compojure project, but I need to handle new users. Where in the Friend workflow should I create non-existent users in my datastore? credential-fn
Is it possible inside ?
+3
Petrus theron
source
to share
1 answer
It is right. credential-fn
from one of my projects now looks something like this:
(defn linkedin-auth [{access-token :access-token :as m}]
(let [options {:query-params {:oauth2_access_token access-token
:format "json"}}
account-info (http-json "https://api.linkedin.com/v1/people/~" options)
email (http-json "https://api.linkedin.com/v1/people/~/email-address" options)]
(register-or-load-from-db
{:roles #{::user}
:identity email
:name (str (:firstName account-info) " " (:lastName account-info))}))))
And the workflow configuration:
(oauth2/workflow {:client-config linkedin-client-config
:uri-config linkedin-uri-config
:credential-fn #'linkedin-auth
:login-uri "/linkedinlogin"})
+2
DanLebrero
source
to share