我终于在我的Clojure Compojure项目上为Twitter和Facebook登录工作了OAuth工作流程,但我需要处理新用户。在Friend工作流程中,我应该在数据存储中创建不存在的用户吗?可能在credential-fn
里面?
答案 0 :(得分:2)
这是正确的。我项目之一的credential-fn
现在看起来像是:
(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))}))))
工作流程配置:
(oauth2/workflow {:client-config linkedin-client-config
:uri-config linkedin-uri-config
:credential-fn #'linkedin-auth
:login-uri "/linkedinlogin"})