implementing permissions to companies
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.users :as users]
|
||||
[auto-ap.parse :as parse]
|
||||
[ring.middleware.multipart-params :as mp]
|
||||
[ring.util.response :as response]
|
||||
@@ -42,7 +43,7 @@
|
||||
(response/resource-response "index.html" {:root "public"}))
|
||||
(GET "/api/oauth" {{:strs [code]} :query-params}
|
||||
(try
|
||||
(let [token (-> "https://accounts.google.com/o/oauth2/token"
|
||||
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
|
||||
(http/post
|
||||
{:form-params {"client_id" google-client-id
|
||||
"client_secret" google-client-secret
|
||||
@@ -50,18 +51,22 @@
|
||||
"redirect_uri" "http://localhost:3449/api/oauth"
|
||||
"grant_type" "authorization_code"}
|
||||
:as :json})
|
||||
:body
|
||||
:access_token)
|
||||
:body)
|
||||
token (:access_token auth)
|
||||
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||
{:headers {"Authorization" (str "Bearer " token)} :as :json})
|
||||
:body
|
||||
:name)
|
||||
]
|
||||
(if token
|
||||
(doto println)
|
||||
)
|
||||
user (users/find-or-insert! {:provider "google"
|
||||
:provider_id (:id profile)})]
|
||||
|
||||
(if (and token user)
|
||||
{:status 301
|
||||
:headers {"Location" (str "/?jwt=" (jwt/sign {:user "test"
|
||||
:exp (time/plus (time/now) (time/days 7))
|
||||
:name profile}
|
||||
:companies (:companies user)
|
||||
:name (:name profile)}
|
||||
jwt-secret
|
||||
{:alg :hs512}))}}
|
||||
{:status 401
|
||||
|
||||
Reference in New Issue
Block a user