using tokens now
This commit is contained in:
parent
15b952865f
commit
afa54c2e5a
|
@ -1 +0,0 @@
|
||||||
/nix/store/g78hiahkl0j6wi51mb6vvp94f7b8lc6v-source
|
|
|
@ -1648,3 +1648,4 @@ export TMP="$NIX_BUILD_TOP"
|
||||||
export TMPDIR="$NIX_BUILD_TOP"
|
export TMPDIR="$NIX_BUILD_TOP"
|
||||||
export TEMP="$NIX_BUILD_TOP"
|
export TEMP="$NIX_BUILD_TOP"
|
||||||
export TEMPDIR="$NIX_BUILD_TOP"
|
export TEMPDIR="$NIX_BUILD_TOP"
|
||||||
|
eval "$shellHook"
|
||||||
|
|
27
main.clj
27
main.clj
|
@ -9,16 +9,16 @@
|
||||||
[api-secret]
|
[api-secret]
|
||||||
(let [encoder (java.util.Base64/getEncoder)
|
(let [encoder (java.util.Base64/getEncoder)
|
||||||
header-raw (->> (json/encode {"alg" "HS512" "typ" "JWT"})
|
header-raw (->> (json/encode {"alg" "HS512" "typ" "JWT"})
|
||||||
.getBytes
|
.getBytes
|
||||||
(.encodeToString encoder))
|
(.encodeToString encoder))
|
||||||
; TODO can't figure out how to apply this with an anon function
|
; TODO can't figure out how to apply this with an anon function
|
||||||
header (clojure.string/replace header-raw "=" "")
|
header (clojure.string/replace header-raw "=" "")
|
||||||
date (-> (sh "date" "-u" "+%s")
|
date (-> (sh "date" "-u" "+%s")
|
||||||
:out
|
:out
|
||||||
(clojure.string/replace "\n" ""))
|
(clojure.string/replace "\n" ""))
|
||||||
payload-raw (->> (json/encode {"iat" date})
|
payload-raw (->> (json/encode {"iat" date})
|
||||||
.getBytes
|
.getBytes
|
||||||
(.encodeToString encoder))
|
(.encodeToString encoder))
|
||||||
; TODO can't figure out how to apply this with an anon function
|
; TODO can't figure out how to apply this with an anon function
|
||||||
payload (clojure.string/replace payload-raw "=" "")
|
payload (clojure.string/replace payload-raw "=" "")
|
||||||
algo "HmacSHA512"
|
algo "HmacSHA512"
|
||||||
|
@ -31,23 +31,22 @@
|
||||||
(clojure.string/replace "/" "_")
|
(clojure.string/replace "/" "_")
|
||||||
(clojure.string/replace "=" "")
|
(clojure.string/replace "=" "")
|
||||||
(clojure.string/replace "+" "-"))]
|
(clojure.string/replace "+" "-"))]
|
||||||
(str header "." payload "." signature))))
|
(str header "." payload "." signature))))
|
||||||
|
|
||||||
(let [token (generate-token (System/getenv secret-token))
|
(let [token (generate-token (System/getenv "token"))
|
||||||
data (-> (curl/get "http://links.mossnet.lan/api/v1/links?searchtags=music" {:headers {"Authorization" (str "Bearer " token)}})
|
data (-> (curl/get "http://links.mossnet.lan/api/v1/links?searchtags=music" {:headers {"Authorization" (str "Bearer " token)}})
|
||||||
(:body)
|
(:body)
|
||||||
(json/parse-string true))
|
(json/parse-string true))
|
||||||
; filter to bandcamp (and maybe others?)
|
; filter to bandcamp (and maybe others?)
|
||||||
filtered-data (mapv (filter (fn [x] (contains? "bandcamp" (get x :url)))) data)]
|
filtered-data (mapv (filter (fn [x] (contains? "bandcamp" (get x :url)))) data)]
|
||||||
filtered-data)
|
filtered-data)
|
||||||
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(println "somestring")
|
(println "somestring")
|
||||||
(.getBytes (str {"iat" (sh "date" "-u" "+%s")}))
|
(.getBytes (str {"iat" (sh "date" "-u" "+%s")}))
|
||||||
(def signature (-> (Mac/getInstance "HmacSHA256")
|
(def signature (-> (Mac/getInstance "HmacSHA256")
|
||||||
(.init (SecretKeySpec. (.getBytes "test secret") "HmacSHA256"))
|
(.init (SecretKeySpec. (.getBytes "test secret") "HmacSHA256"))
|
||||||
(.doFinal (.getBytes (str "header.payload" ) "UTF-8"))))
|
(.doFinal (.getBytes (str "header.payload") "UTF-8"))))
|
||||||
(def sig
|
(def sig
|
||||||
(let [algo "HmacSHA256"
|
(let [algo "HmacSHA256"
|
||||||
mac (Mac/getInstance algo)]
|
mac (Mac/getInstance algo)]
|
||||||
|
|
Loading…
Reference in a new issue