mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 14:56:14 +02:00
🎉 Add github auth provider.
This commit is contained in:
parent
63cc6aecaf
commit
f3b5b07796
9 changed files with 62 additions and 3 deletions
|
@ -113,6 +113,9 @@
|
||||||
(s/def ::gitlab-client-secret ::us/string)
|
(s/def ::gitlab-client-secret ::us/string)
|
||||||
(s/def ::gitlab-base-uri ::us/string)
|
(s/def ::gitlab-base-uri ::us/string)
|
||||||
|
|
||||||
|
(s/def ::github-client-id ::us/string)
|
||||||
|
(s/def ::github-client-secret ::us/string)
|
||||||
|
|
||||||
(s/def ::ldap-auth-host ::us/string)
|
(s/def ::ldap-auth-host ::us/string)
|
||||||
(s/def ::ldap-auth-port ::us/integer)
|
(s/def ::ldap-auth-port ::us/integer)
|
||||||
(s/def ::ldap-bind-dn ::us/string)
|
(s/def ::ldap-bind-dn ::us/string)
|
||||||
|
@ -140,6 +143,8 @@
|
||||||
::google-client-secret
|
::google-client-secret
|
||||||
::gitlab-client-id
|
::gitlab-client-id
|
||||||
::gitlab-client-secret
|
::gitlab-client-secret
|
||||||
|
::github-client-id
|
||||||
|
::github-client-secret
|
||||||
::gitlab-base-uri
|
::gitlab-base-uri
|
||||||
::asserts-enabled
|
::asserts-enabled
|
||||||
::redis-uri
|
::redis-uri
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
|
|
||||||
(defn- create-router
|
(defn- create-router
|
||||||
[{:keys [session rpc google-auth gitlab-auth metrics ldap-auth storage svgparse] :as cfg}]
|
[{:keys [session rpc google-auth gitlab-auth github-auth metrics ldap-auth storage svgparse] :as cfg}]
|
||||||
(rr/router
|
(rr/router
|
||||||
[["/metrics" {:get (:handler metrics)}]
|
[["/metrics" {:get (:handler metrics)}]
|
||||||
|
|
||||||
|
@ -115,7 +115,10 @@
|
||||||
["/google/callback" {:get (:callback-handler google-auth)}]
|
["/google/callback" {:get (:callback-handler google-auth)}]
|
||||||
|
|
||||||
["/gitlab" {:post (:auth-handler gitlab-auth)}]
|
["/gitlab" {:post (:auth-handler gitlab-auth)}]
|
||||||
["/gitlab/callback" {:get (:callback-handler gitlab-auth)}]]
|
["/gitlab/callback" {:get (:callback-handler gitlab-auth)}]
|
||||||
|
|
||||||
|
["/github" {:post (:auth-handler github-auth)}]
|
||||||
|
["/github/callback" {:get (:callback-handler github-auth)}]]
|
||||||
|
|
||||||
["/login" {:post #(auth/login-handler cfg %)}]
|
["/login" {:post #(auth/login-handler cfg %)}]
|
||||||
["/logout" {:post #(auth/logout-handler cfg %)}]
|
["/logout" {:post #(auth/logout-handler cfg %)}]
|
||||||
|
@ -125,4 +128,3 @@
|
||||||
["/rpc" {:middleware [(:middleware session)]}
|
["/rpc" {:middleware [(:middleware session)]}
|
||||||
["/query/:type" {:get (:query-handler rpc)}]
|
["/query/:type" {:get (:query-handler rpc)}]
|
||||||
["/mutation/:type" {:post (:mutation-handler rpc)}]]]]))
|
["/mutation/:type" {:post (:mutation-handler rpc)}]]]]))
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
:metrics (ig/ref :app.metrics/metrics)
|
:metrics (ig/ref :app.metrics/metrics)
|
||||||
:google-auth (ig/ref :app.http.auth/google)
|
:google-auth (ig/ref :app.http.auth/google)
|
||||||
:gitlab-auth (ig/ref :app.http.auth/gitlab)
|
:gitlab-auth (ig/ref :app.http.auth/gitlab)
|
||||||
|
:github-auth (ig/ref :app.http.auth/github)
|
||||||
:ldap-auth (ig/ref :app.http.auth/ldap)
|
:ldap-auth (ig/ref :app.http.auth/ldap)
|
||||||
:svgparse (ig/ref :app.svgparse/handler)
|
:svgparse (ig/ref :app.svgparse/handler)
|
||||||
:storage (ig/ref :app.storage/storage)}
|
:storage (ig/ref :app.storage/storage)}
|
||||||
|
@ -108,6 +109,14 @@
|
||||||
:client-id (:google-client-id config)
|
:client-id (:google-client-id config)
|
||||||
:client-secret (:google-client-secret config)}
|
:client-secret (:google-client-secret config)}
|
||||||
|
|
||||||
|
:app.http.auth/github
|
||||||
|
{:rpc (ig/ref :app.rpc/rpc)
|
||||||
|
:session (ig/ref :app.http.session/session)
|
||||||
|
:tokens (ig/ref :app.tokens/tokens)
|
||||||
|
:public-uri (:public-uri config)
|
||||||
|
:client-id (:github-client-id config)
|
||||||
|
:client-secret (:github-client-secret config)}
|
||||||
|
|
||||||
:app.http.auth/gitlab
|
:app.http.auth/gitlab
|
||||||
{:rpc (ig/ref :app.rpc/rpc)
|
{:rpc (ig/ref :app.rpc/rpc)
|
||||||
:session (ig/ref :app.http.session/session)
|
:session (ig/ref :app.http.session/session)
|
||||||
|
|
|
@ -55,6 +55,8 @@ respective defaults):
|
||||||
- `APP_GITLAB_CLIENT_SECRET=` (default undefined)
|
- `APP_GITLAB_CLIENT_SECRET=` (default undefined)
|
||||||
- `APP_GITLAB_BASE_URI=` (default https://gitlab.com)
|
- `APP_GITLAB_BASE_URI=` (default https://gitlab.com)
|
||||||
|
|
||||||
|
- `APP_GITHUB_CLIENT_ID=` (default undefined)
|
||||||
|
- `APP_GITHUB_CLIENT_SECRET=` (default undefined)
|
||||||
|
|
||||||
## REPL ##
|
## REPL ##
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,15 @@
|
||||||
"es" : "Entrar con Gitlab"
|
"es" : "Entrar con Gitlab"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"auth.login-with-github-submit" : {
|
||||||
|
"used-in" : [ "src/app/main/ui/auth/login.cljs:154" ],
|
||||||
|
"translations" : {
|
||||||
|
"en" : "Login with Github",
|
||||||
|
"fr" : "Se connecter via Github",
|
||||||
|
"ru" : "Вход через Gitnub",
|
||||||
|
"es" : "Entrar con Github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"auth.login-with-ldap-submit" : {
|
"auth.login-with-ldap-submit" : {
|
||||||
"used-in" : [ "src/app/main/ui/auth/login.cljs:105" ],
|
"used-in" : [ "src/app/main/ui/auth/login.cljs:105" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
|
|
|
@ -79,4 +79,15 @@
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-github-auth {
|
||||||
|
margin-bottom: $medium;
|
||||||
|
text-decoration: none;
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
(def demo-warning (obj/get global "appDemoWarning" false))
|
(def demo-warning (obj/get global "appDemoWarning" false))
|
||||||
(def google-client-id (obj/get global "appGoogleClientID" nil))
|
(def google-client-id (obj/get global "appGoogleClientID" nil))
|
||||||
(def gitlab-client-id (obj/get global "appGitlabClientID" nil))
|
(def gitlab-client-id (obj/get global "appGitlabClientID" nil))
|
||||||
|
(def github-client-id (obj/get global "appGithubClientID" nil))
|
||||||
(def login-with-ldap (obj/get global "appLoginWithLDAP" false))
|
(def login-with-ldap (obj/get global "appLoginWithLDAP" false))
|
||||||
(def worker-uri (obj/get global "appWorkerURI" "/js/worker.js"))
|
(def worker-uri (obj/get global "appWorkerURI" "/js/worker.js"))
|
||||||
(def public-uri (or (obj/get global "appPublicURI")
|
(def public-uri (or (obj/get global "appPublicURI")
|
||||||
|
|
|
@ -91,6 +91,12 @@
|
||||||
(->> (http/send! {:method :post :uri uri})
|
(->> (http/send! {:method :post :uri uri})
|
||||||
(rx/mapcat handle-response))))
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
|
(defmethod mutation :login-with-github
|
||||||
|
[id params]
|
||||||
|
(let [uri (str cfg/public-uri "/api/oauth/github")]
|
||||||
|
(->> (http/send! {:method :post :uri uri})
|
||||||
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
(defmethod mutation :upload-file-media-object
|
(defmethod mutation :upload-file-media-object
|
||||||
[id params]
|
[id params]
|
||||||
(let [form (js/FormData.)]
|
(let [form (js/FormData.)]
|
||||||
|
|
|
@ -46,6 +46,13 @@
|
||||||
(rx/subs (fn [{:keys [redirect-uri] :as rsp}]
|
(rx/subs (fn [{:keys [redirect-uri] :as rsp}]
|
||||||
(.replace js/location redirect-uri)))))
|
(.replace js/location redirect-uri)))))
|
||||||
|
|
||||||
|
(defn- login-with-github
|
||||||
|
[event]
|
||||||
|
(dom/prevent-default event)
|
||||||
|
(->> (rp/mutation! :login-with-github {})
|
||||||
|
(rx/subs (fn [{:keys [redirect-uri] :as rsp}]
|
||||||
|
(.replace js/location redirect-uri)))))
|
||||||
|
|
||||||
(mf/defc login-form
|
(mf/defc login-form
|
||||||
[]
|
[]
|
||||||
(let [error? (mf/use-state false)
|
(let [error? (mf/use-state false)
|
||||||
|
@ -138,6 +145,13 @@
|
||||||
{:src "/images/icons/brand-gitlab.svg"}]
|
{:src "/images/icons/brand-gitlab.svg"}]
|
||||||
(tr "auth.login-with-gitlab-submit")])
|
(tr "auth.login-with-gitlab-submit")])
|
||||||
|
|
||||||
|
(when cfg/github-client-id
|
||||||
|
[:a.btn-ocean.btn-large.btn-github-auth
|
||||||
|
{:on-click login-with-github}
|
||||||
|
[:img.logo
|
||||||
|
{:src "/images/icons/brand-github.svg"}]
|
||||||
|
(tr "auth.login-with-github-submit")])
|
||||||
|
|
||||||
[:div.links.demo
|
[:div.links.demo
|
||||||
[:div.link-entry
|
[:div.link-entry
|
||||||
[:span (tr "auth.create-demo-profile") " "]
|
[:span (tr "auth.create-demo-profile") " "]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue