diff options
author | Tim <contact@bytim.eu> | 2025-05-10 10:59:30 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-05-10 10:59:30 +0200 |
commit | 77594fd2b62e4ea3e6a55fed2dabcce50e618bd3 (patch) | |
tree | 5ddfa7589b5d9a46dbd40d5eea49c3e782c22d1a /src/chef/routes.clj | |
parent | 79e32a55801fc53c8d60843c6676ca05cc899299 (diff) | |
download | chef-77594fd2b62e4ea3e6a55fed2dabcce50e618bd3.tar.xz chef-77594fd2b62e4ea3e6a55fed2dabcce50e618bd3.zip |
Add oauth for admin interface
Diffstat (limited to 'src/chef/routes.clj')
-rw-r--r-- | src/chef/routes.clj | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/chef/routes.clj b/src/chef/routes.clj index 51c721a..c2fd6c7 100644 --- a/src/chef/routes.clj +++ b/src/chef/routes.clj @@ -1,5 +1,10 @@ (ns chef.routes (:require [reitit.ring :as rring] + [ring.middleware.oauth2 :as rmoauth2] + [ring.middleware.params :as rmparams] + [ring.middleware.session :as rmsession] + [dotenv :as env] + [clojure.string :as cstr] [chef.pages.home :as cphome] [chef.pages.admin :as cpadmin])) @@ -8,6 +13,17 @@ ["/admin/" {:get {:handler cpadmin/handler}}] ["/static/*" (rring/create-resource-handler)]]) -(def ring-handler (-> router - rring/router - (rring/ring-handler (rring/redirect-trailing-slash-handler)))) +(def ring-handler (delay (-> router + rring/router + (rring/ring-handler (rring/redirect-trailing-slash-handler)) + (rmoauth2/wrap-oauth2 {:auth {:authorize-uri (env/env "OAUTH_AUTH_URI") + :access-token-uri (env/env "OAUTH_ACCESS_TOKEN_URI") + :client-id (env/env "OAUTH_CLIENT_ID") + :client-secret (env/env "OAUTH_CLIENT_SECRET") + :scopes (cstr/split (env/env "OAUTH_SCOPES") #",") + :launch-uri "/auth" + :redirect-uri "/auth/callback" + :landing-uri "/" + :pkce? true}}) + rmparams/wrap-params + rmsession/wrap-session))) |