Skip to content

Commit 68c77f5

Browse files
author
awb99
committed
demo using only webly
1 parent 35bb4b6 commit 68c77f5

23 files changed

+84
-186
lines changed

TODO.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
- https://docs.github.com/en/rest/reference/users
66

7-
https://rapidapi.com/category/Finance
87

98
# links
109

demo/deps.edn

+19-32
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,30 @@
33
"target/webly"]
44

55
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
6-
org.pinkgorilla/goldly {:mvn/version "0.4.621"}
6+
org.pinkgorilla/webly {:mvn/version "0.5.655"}
77
org.pinkgorilla/ui-tailwind {:mvn/version "0.0.5"}
8-
org.pinkgorilla/ui-repl {:mvn/version "0.0.72"}
98
org.pinkgorilla/oauth2 {:local/root "../" :deps/manifest :deps}
109
}
1110

1211

13-
:aliases {:demo
14-
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}
15-
cider/cider-nrepl {:mvn/version "0.28.3"}}
16-
:exec-fn modular.system/start!
17-
:exec-args {:profile "jetty"
18-
:config ["webly/config.edn"
19-
"goldly/config.edn"
20-
"oauth2/config.edn" ; oauth2 endpoints
21-
"demo-config.edn"
22-
"/home/florian/repo/myLinux/myvault/goldly/oauth2-localhost.edn" ; oauth2 secrets
23-
]
24-
:services "demo-services.edn" #_"goldly/services.edn"}}
25-
26-
:npm-install
27-
{:exec-fn goldly.app.build/goldly-build
28-
:exec-args {:profile "npm-install"}}
29-
30-
:compile
31-
{:exec-fn goldly.app.build/goldly-build
32-
:exec-args {:profile "compile2"}}
33-
34-
:run
35-
{:exec-fn modular.system/start!
36-
:exec-args {:config ["webly/config.edn"
37-
"goldly/config.edn"
38-
"oauth2/config.edn"
39-
"demo-config.edn" ; oauth2 endpoints
40-
"/home/florian/repo/myLinux/myvault/goldly/oauth2-localhost.edn" ; oauth2 secrets
41-
]
42-
:services "demo-run.edn"}}
12+
:aliases {:webly {:exec-fn webly.app.app/webly-build
13+
:exec-args {:config [{}]
14+
:profile "npm-install"}}
15+
16+
:npm-install {:exec-args {:profile "npm-install"}}
17+
:compile {:exec-args {:profile "compile2"}}
18+
:release {:exec-args {:profile "release"}}
19+
:release-adv {:exec-args {:profile "release-adv"}}
20+
:static {:exec-args {:profile "static"}}
21+
:ci {:exec-args {:profile "ci"}}
22+
23+
:run {:exec-fn modular.system/start!
24+
:exec-args {:profile "jetty"
25+
:config ["oauth2/config.edn" ; oauth2 endpoints
26+
"demo-config.edn"
27+
"/home/florian/repo/myLinux/myvault/goldly/oauth2-localhost.edn" ; oauth2 secrets
28+
]
29+
:services "demo-services.edn"}}
4330

4431
;; token info
4532
:token-info-xero {:exec-args {:run demo.token/token-info

demo/resources/demo-config.edn

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
{:goldly {; build
2-
:lazy true
3-
; run
4-
:autoload-cljs-dir []
5-
; it should not be necessary to define routes, as
6-
; we use the extension system here.
7-
; todo: fix this bug in goldly.
8-
:routes {:app {;"" demo.page.main/main-page
9-
}
10-
:api {}}}
11-
12-
:users {:demo {:roles #{:logistic}
1+
{:users {:demo {:roles #{:logistic}
132
:password "a231498f6c1f441aa98482ea0b224ffa" ; "1234"
143
:email ["[email protected]"]}
154
:boss {:roles #{:logistic :supervisor :accounting}

demo/resources/demo-run.edn

-15
This file was deleted.

demo/resources/demo-services.edn

+4-17
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,13 @@
66
:timbre {:start (modular.log/timbre-config!
77
(:timbre/clj (deref (clip/ref :config))))}
88

9-
; goldly service returns {:ns-clj :webly ; this are used to start clj-require and webly
10-
; :ws-watch :cljs-watch} ; this is used when stopping goldly
11-
:goldly {:start (goldly.app.run/start-goldly
12-
(deref (clip/ref :config))
13-
(:profile #ref [:modular]))
14-
:stop (goldly.app.run/stop-goldly this)
15-
;:post-start (goldly-docs/print-version)
16-
}
17-
18-
; load the :ns-clj defined by the user
19-
:ns-require {:start (modular.require/require-namespaces
20-
(:ns-clj (deref (clip/ref :config))))}
219

2210
:webly {:start (webly.app.app/start-webly
23-
(:webly (clip/ref :goldly)) ; use webly config generated by goldly.
24-
(:profile #ref [:modular]))
25-
:stop (webly.app.app/stop-webly this)}
11+
(deref (clip/ref :config))
12+
(:profile #ref [:modular]))
13+
:stop (webly.app.app/stop-webly this)}
14+
2615

27-
:nrepl {:start (nrepl.server/start-server :bind "0.0.0.0" :port 9100)
28-
:stop (.close this)}
2916

3017
;
3118
}}

demo/resources/ext/demo.edn

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{:name "demo"
2-
:cljs-routes {"" demo.page.oauth2/page-oauth2
3-
}
4-
:sci-cljs-ns [demo.page.oauth2
5-
demo.helper.ui
6-
demo.helper.oauth2]
7-
8-
9-
}
2+
; build
3+
:lazy true
4+
:cljs-namespace [demo.page.oauth2]
5+
:cljs-ns-bindings {'demo.page.oauth2 {'page-oauth2 demo.page.oauth2/page-oauth2}}
6+
; run
7+
:cljs-routes {"" demo.page.oauth2/page-oauth2}}

demo/src/demo/page/oauth2.cljs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
;; OAUTH
1111
(defn demo-oauth []
1212
[block2 "oauth2"
13+
[:h1 "users"]
14+
[:p "user: florian pwd: 1234"]
15+
[:p "user: boss pwd: 1234"]
1316
[user-login]
1417
[:div.border.border-blue-500.border-2.border-round ; .overflow-scroll
1518
[provider-status-grid [:google :github :xero :woo :wordpress
@@ -19,4 +22,6 @@
1922
(defn page-oauth2 [_]
2023
[:div.w-full.h-full
2124
[link-fn #(rf/dispatch [:login/dialog]) "login"]
22-
[demo-oauth]])
25+
[demo-oauth]])
26+
27+

deps.edn

+1-14
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,13 @@
2828
clj-jwt/clj-jwt {:mvn/version "0.1.1"}; https://github.com/liquidz/clj-jwt
2929
ring-oauth2/ring-oauth2 {:mvn/version "0.1.5"}
3030
clj-oauth/clj-oauth {:mvn/version "1.5.2"}; copied over from REST
31-
3231
; pink-gorilla dependencies
3332
org.pinkgorilla/modular {:mvn/version "0.0.40"}
3433
org.pinkgorilla/permission {:mvn/version "0.0.15"}
35-
; TODO: move frontend->somewhere else.
36-
;modular/frontend {:local/root "../frontend" :deps/manifest :deps}
3734
org.pinkgorilla/websocket {:mvn/version "0.0.9"}}
3835

39-
4036
:aliases
41-
{:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}
42-
:main-opts ["-m" "antq.core"]}
43-
44-
:nrepl {:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}
45-
cider/cider-nrepl {:mvn/version "0.28.3"}
46-
;cider/nrepl {:mvn/version "0.3.0"}
47-
}
48-
:main-opts ["-m" "nrepl.cmdline"]}
49-
50-
:test {:extra-paths ["test"]
37+
{:test {:extra-paths ["test"]
5138
:extra-deps {io.github.cognitect-labs/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git"
5239
:sha "cc75980b43011773162b485f46f939dc5fba91e4"}}
5340
:main-opts ["-m" "cognitect.test-runner"]

resources/ext/oauth2.edn

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
'modular.oauth2.user.view {'user-login modular.oauth2.user.view/user-login}
1111
'modular.oauth2.token.ui {'provider-status-grid modular.oauth2.token.ui/provider-status-grid}}
1212
; run
13-
:autoload-clj-ns [; websocket handler dont have (yet) a extension loader
14-
modular.oauth2.local.handler
15-
modular.oauth2 ; side-effects
16-
]
17-
1813
:api-routes {"oauth2/" {["start/" :provider] {:get modular.oauth2.handler/handler-oauth2-start-wrapped}
1914
"token" {:get modular.oauth2.handler/token-handler-wrapped}
2015
; ["redirect/" :provider] {:get :oauth2/redirect}

src/modular/oauth2/authorize/start_handler.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
[modular.oauth2.config :refer [entire-config]]
66
[modular.oauth2.provider :refer [url-authorize]]))
77

8-
(defn handler-oauth2-start
8+
(defn handler-oauth2-start
99
"this handler is opened in a browser-popup window.
1010
It redirects to the oauth2 start url of the provider"
1111
[req]
1212
#_(info "oauth2/authorize-start: "
13-
"params:" (:params req)
14-
"query-params:" (:query-params req))
13+
"params:" (:params req)
14+
"query-params:" (:query-params req))
1515
;(info "oauth2/authorize-start: req:" req)
1616
(let [{:keys [scheme server-name server-port uri]} req
1717
current-url (get-in req [:query-params "current-url"])

src/modular/oauth2/config.clj

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns modular.oauth2.config
2-
(:require
2+
(:require
33
[modular.config :refer [get-in-config config-atom]]))
44

55
;; this config is here, so that we do not use modular.config in many different places.
@@ -8,11 +8,9 @@
88
(defn token-path []
99
(get-in-config [:oauth2 :token-path]))
1010

11-
1211
(defn provider-config [config provider]
1312
(get-in config [:oauth2 provider]))
1413

15-
1614
;; local auth (username/password)
1715

1816
(defn local-token-secret []
@@ -26,7 +24,6 @@
2624
(defn token-prefix [provider]
2725
(get-in-config [:oauth2 provider :token-prefix]))
2826

29-
3027
;; full config
3128
;; TODO: needs to be refactored
3229
;; used in:
@@ -38,24 +35,18 @@
3835
(defn get-config-server [server-profile-kw]
3936
(get-in-config [:oauth2 :server server-profile-kw]))
4037

41-
42-
(defn get-config-user
38+
(defn get-config-user
4339
([]
4440
(get-config-user :default))
4541
([user-id-kw]
4642
(get-in-config [:oauth2 :user user-id-kw])))
4743

48-
4944
(defn entire-config []
5045
@config-atom)
5146

52-
53-
54-
55-
(comment
47+
(comment
5648
(token-path)
57-
58-
59-
;
49+
50+
;
6051
)
6152

src/modular/oauth2/config.cljs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
(ns modular.oauth2.config)
22

3-
4-
5-
(def config
3+
(def config
64
(atom {:name "Webly" ; shown in popup-window
7-
85
}))
9-
10-
116
(defn app-name []
127
(:name @config))

src/modular/oauth2/date.cljc

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; now
1111

1212
(defn now-instant []
13-
(t/now))
13+
(t/now))
1414

1515
(defn add-seconds [dt n]
1616
(t/>> dt (t/new-duration n :seconds)))
@@ -21,9 +21,9 @@
2121
(comment
2222
(now-instant)
2323
(-> (now-instant) (add-seconds 1800))
24-
24+
2525
(t/> (-> (now-instant) (add-minutes -1))
2626
(now-instant))
2727

2828
;
29-
)
29+
)

src/modular/oauth2/handler.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
[modular.oauth2.authorize.start-handler :refer [handler-oauth2-start]]
66
[modular.oauth2.authorize.redirect-handler :refer [handler-oauth2-redirect]]
77
[modular.oauth2.authorize.token-handler :refer [token-handler]]
8-
[modular.oauth2.token.save-handler :refer [handler-oauth2-save]]))
8+
[modular.oauth2.token.save-handler :refer [handler-oauth2-save]]
9+
[modular.oauth2.local.handler] ; side effects
10+
[modular.oauth2] ; side effects
11+
))
912

1013
; wrapping not needed and fucks up the redirection
1114

src/modular/oauth2/local/pass.clj

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
[buddy.sign.jwt :as jwt]
88
;[no.nsd.clj-jwt :as clj-jwt]
99
[modular.permission.user :refer [get-user]]
10-
[modular.oauth2.config :refer [local-token-secret user-list]]
11-
))
10+
[modular.oauth2.config :refer [local-token-secret user-list]]))
1211

1312
(defn pwd-hash [pwd]
1413
(-> (hash/blake2b-128 pwd)

src/modular/oauth2/middleware.clj

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
[ring.middleware.oauth2 :refer [wrap-oauth2]]
88
[modular.writer :refer [write-status]]
99
[modular.oauth2.provider :refer [ring-oauth2-config]]
10-
[modular.oauth2.config :refer [entire-config]]
11-
))
10+
[modular.oauth2.config :refer [entire-config]]))
1211

1312
; https://github.com/weavejester/ring-oauth2
1413

src/modular/oauth2/provider/amazon.cljc

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
; https://sellercentral.amazon.com/s
1010
; https://sellingpartnerapi-na.amazon.com
1111

12-
1312
; Amazon Vendor Central has a new, modern Selling Partner API (SP-API). The new API supports both sellers and vendors alike within a unified platform. Seller Central has had API access under the Amazon Marketplace Web Service (MWS) umbrella for years.
1413
; IAM ARN. This is the identifier for the AWS IAM user we created in the last post (it should look something like arn:aws:iam::012345678987:user/sp-api…and no, that's not my real info ;)
1514
; Again, go to Partner Network > Develop Apps, then open the dropdown next to the Edit button for your app and select Authorize. This will bring you to the authorization page, where you can generate a Login with Amazon (LWA) refresh token. This token lasts a long time, and will be used to generate new API access tokens (which expire quickly). Save the LWA refresh token somewhere—you're going to need it! Note that from the Develop Apps page, you can click View to see your LWA credentials…you'll need those too.

src/modular/oauth2/token/identity.clj

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
:email))]
1212
id))
1313

14-
1514
(comment
1615
(require '[modular.oauth2.token.store :refer [load-token]])
1716
; providers that have oidc

0 commit comments

Comments
 (0)