3
我終於在我的Clojure Compojure項目中獲得了用於Twitter和Facebook登錄的OAuth工作流程,但我需要處理新用戶。在Friend工作流中,我應該在數據存儲中創建不存在的用戶?或許credential-fn
?哪裏可以在Clojure中使用cemerick/friend創建OAuth用戶
我終於在我的Clojure Compojure項目中獲得了用於Twitter和Facebook登錄的OAuth工作流程,但我需要處理新用戶。在Friend工作流中,我應該在數據存儲中創建不存在的用戶?或許credential-fn
?哪裏可以在Clojure中使用cemerick/friend創建OAuth用戶
這是正確的。從我的項目之一的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"})
謝謝,@dAni。我將如何訪問':session'或當前登錄的'credential-fn'用戶,以便我們可以將他們的標識符與現有帳戶相關聯(如果他們已經登錄)? – 2014-09-29 09:54:25
也許我可以通過添加額外的工作流fn來解析各種提供者的憑證-fn的輸出來實現這一目標? – 2014-09-29 10:02:15
'credential-fn'必須接受一個參數,其中將包含用戶憑證映射。用戶憑證映射取決於所使用的身份驗證方法。在friend-oauth2的情況下,地圖包含訪問令牌,然後您可以使用它訪問oauth提供程序中的其他信息(如您在示例中所見)。憑證結果作爲會話信息的一部分結束 – DanLebrero 2014-09-29 10:27:21