improving login flow.

This commit is contained in:
Bryce Covert
2018-04-04 07:13:35 -07:00
parent ff7cc1d024
commit 2382c48bd0
5 changed files with 57 additions and 11 deletions

View File

@@ -17,6 +17,7 @@
[clj-fuzzy.metrics :as m]
[clj-http.client :as http]
[clj-time.core :as time]
[config.core :refer [env]]
[buddy.auth :refer [authenticated?]]
@@ -42,16 +43,18 @@
(GET "/" []
(response/resource-response "index.html" {:root "public"}))
(GET "/api/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers}
(try
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
(http/post
{:form-params {"client_id" google-client-id
"client_secret" google-client-secret
"code" code
"redirect_uri" (str (name scheme) "://" host "/api/oauth")
"redirect_uri" (str (:scheme env) "://" host "/api/oauth")
"grant_type" "authorization_code"}
:as :json})
:body)
_ (println auth)
token (:access_token auth)
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
{:headers {"Authorization" (str "Bearer " token)} :as :json})
@@ -74,7 +77,7 @@
(catch Exception e
{:status 401
:body (str "Couldn't authenticate " (.toString e))})))
:body (str "Couldn't authenticate " (.toString e))})))
(route/resources "/")
(routes (ANY "*" [] (response/resource-response "index.html" {:root "public"}))))