parent
a90c9569e2
commit
12671cd2c3
|
@ -12,8 +12,7 @@
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(defn root-path []
|
|
||||||
(if (env :on-testnet) "/test" "/"))
|
|
||||||
|
|
||||||
(defn- create-user [token user]
|
(defn- create-user [token user]
|
||||||
(let [{name :name
|
(let [{name :name
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
(create-user token user))))
|
(create-user token user))))
|
||||||
|
|
||||||
(defroutes redirect-routes
|
(defroutes redirect-routes
|
||||||
(GET (str (root-path) "callback") [code state]
|
(GET "/callback" [code state]
|
||||||
(let [resp (github/post-for-token code state)
|
(let [resp (github/post-for-token code state)
|
||||||
body (keywordize-keys (codec/form-decode (:body resp)))
|
body (keywordize-keys (codec/form-decode (:body resp)))
|
||||||
scope (:scope body)
|
scope (:scope body)
|
||||||
|
@ -42,10 +41,10 @@
|
||||||
(log/debug "github sign-in callback, response body:" body)
|
(log/debug "github sign-in callback, response body:" body)
|
||||||
(if (:error body)
|
(if (:error body)
|
||||||
;; Why does Mist browser sends two redirects at the same time? The latter results in 401 error.
|
;; Why does Mist browser sends two redirects at the same time? The latter results in 401 error.
|
||||||
(response/redirect (root-path))
|
(response/redirect "/")
|
||||||
(let [admin-token? (str/includes? scope "repo")
|
(let [admin-token? (str/includes? scope "repo")
|
||||||
token-key (if admin-token? :admin-token :token)
|
token-key (if admin-token? :admin-token :token)
|
||||||
user (assoc (get-or-create-user access-token)
|
user (assoc (get-or-create-user access-token)
|
||||||
token-key access-token)]
|
token-key access-token)]
|
||||||
(assoc (response/redirect (root-path))
|
(assoc (response/redirect "/")
|
||||||
:session {:identity user}))))))
|
:session {:identity user}))))))
|
||||||
|
|
Loading…
Reference in New Issue