new approach for oauth
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
[ring.middleware.edn :refer [wrap-edn-params]]
|
||||
[clojure.java.jdbc :as j]
|
||||
[clj-fuzzy.metrics :as m]
|
||||
[clj-http.client :as http]
|
||||
|
||||
[auto-ap.db.companies :as companies]))
|
||||
(defn best-match [companies company-identifier]
|
||||
(->> companies
|
||||
@@ -24,8 +26,29 @@
|
||||
|
||||
ffirst))
|
||||
|
||||
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
|
||||
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
|
||||
|
||||
(defroutes app-routes
|
||||
(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" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
|
||||
Reference in New Issue
Block a user