diff --git a/.direnv/flake-inputs/g78hiahkl0j6wi51mb6vvp94f7b8lc6v-source b/.direnv/flake-inputs/g78hiahkl0j6wi51mb6vvp94f7b8lc6v-source deleted file mode 120000 index 0920b51..0000000 --- a/.direnv/flake-inputs/g78hiahkl0j6wi51mb6vvp94f7b8lc6v-source +++ /dev/null @@ -1 +0,0 @@ -/nix/store/g78hiahkl0j6wi51mb6vvp94f7b8lc6v-source \ No newline at end of file diff --git a/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc b/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc index 592f105..1e358f3 100644 --- a/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc +++ b/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc @@ -1648,3 +1648,4 @@ export TMP="$NIX_BUILD_TOP" export TMPDIR="$NIX_BUILD_TOP" export TEMP="$NIX_BUILD_TOP" export TEMPDIR="$NIX_BUILD_TOP" +eval "$shellHook" diff --git a/main.clj b/main.clj index 46a8366..49f9da5 100644 --- a/main.clj +++ b/main.clj @@ -9,16 +9,16 @@ [api-secret] (let [encoder (java.util.Base64/getEncoder) header-raw (->> (json/encode {"alg" "HS512" "typ" "JWT"}) - .getBytes - (.encodeToString encoder)) + .getBytes + (.encodeToString encoder)) ; TODO can't figure out how to apply this with an anon function header (clojure.string/replace header-raw "=" "") - date (-> (sh "date" "-u" "+%s") - :out - (clojure.string/replace "\n" "")) + date (-> (sh "date" "-u" "+%s") + :out + (clojure.string/replace "\n" "")) payload-raw (->> (json/encode {"iat" date}) - .getBytes - (.encodeToString encoder)) + .getBytes + (.encodeToString encoder)) ; TODO can't figure out how to apply this with an anon function payload (clojure.string/replace payload-raw "=" "") algo "HmacSHA512" @@ -26,29 +26,28 @@ (.init mac (SecretKeySpec. (.getBytes api-secret) algo)) (let [sig (->> (.doFinal mac (.getBytes (str header "." payload))) (.encodeToString encoder)) - signature (-> sig + signature (-> sig ; TODO should do url encode here (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)}}) - (:body) - (json/parse-string true)) + (:body) + (json/parse-string true)) ; 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) - -(comment +(comment (println "somestring") (.getBytes (str {"iat" (sh "date" "-u" "+%s")})) (def signature (-> (Mac/getInstance "HmacSHA256") - (.init (SecretKeySpec. (.getBytes "test secret") "HmacSHA256")) - (.doFinal (.getBytes (str "header.payload" ) "UTF-8")))) - (def sig + (.init (SecretKeySpec. (.getBytes "test secret") "HmacSHA256")) + (.doFinal (.getBytes (str "header.payload") "UTF-8")))) + (def sig (let [algo "HmacSHA256" mac (Mac/getInstance algo)] (.init mac (SecretKeySpec. (.getBytes "test secret") algo))