new approach for oauth
This commit is contained in:
@@ -16,11 +16,11 @@
|
|||||||
[dk.ative/docjure "1.12.0"]
|
[dk.ative/docjure "1.12.0"]
|
||||||
[org.clojure/java.jdbc "0.7.3"]
|
[org.clojure/java.jdbc "0.7.3"]
|
||||||
[cljsjs/dropzone "4.3.0-0"]
|
[cljsjs/dropzone "4.3.0-0"]
|
||||||
[cljsjs/auth0-lock "10.24.1-0"]
|
|
||||||
[clj-fuzzy "0.4.1"]
|
[clj-fuzzy "0.4.1"]
|
||||||
;; https://mvnrepository.com/artifact/postgresql/postgresql
|
;; https://mvnrepository.com/artifact/postgresql/postgresql
|
||||||
[postgresql/postgresql "9.3-1102.jdbc41"]
|
[postgresql/postgresql "9.3-1102.jdbc41"]
|
||||||
[cljs-http "0.1.44"]
|
[cljs-http "0.1.44"]
|
||||||
|
[clj-http "3.7.0"]
|
||||||
[org.clojure/core.async "0.3.465"]
|
[org.clojure/core.async "0.3.465"]
|
||||||
[fogus/ring-edn "0.3.0"]]
|
[fogus/ring-edn "0.3.0"]]
|
||||||
:plugins [[lein-ring "0.9.7"]
|
:plugins [[lein-ring "0.9.7"]
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
[ring.middleware.edn :refer [wrap-edn-params]]
|
[ring.middleware.edn :refer [wrap-edn-params]]
|
||||||
[clojure.java.jdbc :as j]
|
[clojure.java.jdbc :as j]
|
||||||
[clj-fuzzy.metrics :as m]
|
[clj-fuzzy.metrics :as m]
|
||||||
|
[clj-http.client :as http]
|
||||||
|
|
||||||
[auto-ap.db.companies :as companies]))
|
[auto-ap.db.companies :as companies]))
|
||||||
(defn best-match [companies company-identifier]
|
(defn best-match [companies company-identifier]
|
||||||
(->> companies
|
(->> companies
|
||||||
@@ -24,8 +26,29 @@
|
|||||||
|
|
||||||
ffirst))
|
ffirst))
|
||||||
|
|
||||||
|
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
|
||||||
|
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
|
||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
(GET "/" [] (response/resource-response "index.html" {:root "public"}))
|
(GET "/" [] (response/resource-response "index.html" {:root "public"}))
|
||||||
|
(GET "/api/oauth" {{:strs [code]} :query-params}
|
||||||
|
(try
|
||||||
|
(let [result (-> "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" "http://localhost:3449/api/oauth"
|
||||||
|
"grant_type" "authorization_code"}
|
||||||
|
:as :json})
|
||||||
|
:body
|
||||||
|
:access_token)]
|
||||||
|
{:status 200
|
||||||
|
:body result})
|
||||||
|
(catch Exception e
|
||||||
|
(println e)
|
||||||
|
{:status 401
|
||||||
|
:body "Couldn't authenticate"})))
|
||||||
(GET "/api/invoices" []
|
(GET "/api/invoices" []
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-all))
|
:body (pr-str (invoices/get-all))
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[cljs.reader :as edn]
|
[cljs.reader :as edn]
|
||||||
[cljsjs.dropzone :as dz]
|
[cljsjs.dropzone :as dz]
|
||||||
[cljsjs.auth0-lock :as a0]
|
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[cljs-http.client :as http]
|
[cljs-http.client :as http]
|
||||||
@@ -218,36 +217,14 @@
|
|||||||
[:i.fa.fa-spin.fa-spinner])
|
[:i.fa.fa-spin.fa-spinner])
|
||||||
"Save"]]]]]))
|
"Save"]]]]]))
|
||||||
|
|
||||||
(def login
|
(defn login-url []
|
||||||
(let [lock (reagent/atom nil)
|
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
||||||
user (re-frame/subscribe [::subs/user])]
|
redirect-uri "http%3A%2F%2Flocalhost%3A3449%2Fapi%2Foauth"]
|
||||||
(with-meta (fn []
|
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"))
|
||||||
[:a {:class "navbar-link login" :on-click (fn [x e] (.preventDefault e) (.show @lock)) } (or (@user "name") "Login")])
|
)
|
||||||
{:component-did-mount (fn [this]
|
(defn login []
|
||||||
(let [l (js/Auth0Lock.
|
(let [user (re-frame/subscribe [::subs/user])]
|
||||||
"twbXfoLvL0tKTR6GWORoM-ss51wM1zXZ",
|
[:a {:class "navbar-link login" :href (login-url)} (or (get @user "name") "Login")]))
|
||||||
"app82488100.auth0.com"
|
|
||||||
(clj->js {
|
|
||||||
:rememberLastLogin false,
|
|
||||||
:socialButtonStyle "big",
|
|
||||||
:oidcConformant true,
|
|
||||||
:auth {
|
|
||||||
:audience "https://app82488100.auth0.com/api/v2/",
|
|
||||||
:params {:scope "openid email profile"},
|
|
||||||
:responseType "token",
|
|
||||||
:redirect true,
|
|
||||||
:redirectUrl "http://localhost:3449"
|
|
||||||
}
|
|
||||||
:languageDictionary {:title "Auto AP"},
|
|
||||||
:language "en"
|
|
||||||
:theme {:primaryColor "#3A99D8"}
|
|
||||||
}))]
|
|
||||||
(.on l "authenticated" (fn [result]
|
|
||||||
(.getUserInfo l (.-accessToken result )
|
|
||||||
(fn [err profile]
|
|
||||||
(re-frame/dispatch [::events/logged-in (.-accessToken result) (js->clj profile)])))))
|
|
||||||
|
|
||||||
(reset! lock l)))})))
|
|
||||||
|
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
(let [company (re-frame/subscribe [::subs/company])
|
(let [company (re-frame/subscribe [::subs/company])
|
||||||
|
|||||||
Reference in New Issue
Block a user