Last active
August 27, 2023 18:17
-
-
Save ruseel/2b94622289b7e96e8d0c83ae01df29f0 to your computer and use it in GitHub Desktop.
Revisions
-
ruseel revised this gist
Feb 27, 2020 . 1 changed file with 33 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,40 +1,54 @@ ;; this worked for me ;; (defn access-token [] (-> (client/post (str base-url "/auth/realms/" realm "/protocol/openid-connect/token") {:accept :json :form-params {"client_id" "admin-cli" "username" some-username "password" default-password "grant_type" "password"}}) :body (json/read-str :key-fn keyword) :access_token)) (defn list-users [] (-> (client/get (str base-url "/auth/admin/realms/" realm "/users") {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])}}) :body (json/read-str :key-fn keyword))) (defn create-user [{:keys [email id name]}] (-> (client/post (str base-url "/auth/admin/realms/" realm "/users") {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])} :content-type "application/json" :body (json/write-str {:email email :username id})}))) (defn update-user [{:keys [id] :as m}] (client/put (str base-url "/auth/admin/realms/" realm "/users/" id) {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])} :content-type "application/json" :body (json/write-str m)})) (defn user-enable [m] (update-user (assoc m :enabled true))) (defn reset-password [{:keys [id password]}] (-> (client/put (str base-url "/auth/admin/realms/" realm "/users/" id "/reset-password") {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])} :content-type "application/json" :body (json/write-str {"type" "password" "value" password "temporary" false})}))) -
ruseel revised this gist
Feb 27, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,8 @@ ;; ;; https://www.keycloak.org/docs-api/9.0/rest-api/#_users_resource ;; ;; this is working on my keycloak ;; (defn create-user [] (-> -
ruseel created this gist
Feb 27, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ (def base-url "https://keyloack.of.myown.com") (defn access-token [] (-> (client/post (str base-url "/auth/realms/callcenter/protocol/openid-connect/token") {:accept :json :form-params {"client_id" "admin-cli" "username" "admin-some-realm" "password" "some-password" "grant_type" "password"}}) :body (json/read-str :key-fn keyword) :access_token)) (access-token) (defn list-users [] (-> (client/get (str base-url "/auth/admin/realms/<REALM>/users") {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])}}) :body (json/read-str :key-fn keyword))) ;; ;; https://www.keycloak.org/docs-api/9.0/rest-api/#_users_resource ;; name `rep` ;; (defn create-user [] (-> (client/post (str base-url "/auth/admin/realms/<REALM>/users") {:headers {"Authorization" (clojure.string/join " " ["bearer" (access-token)])} :content-type "application/json" :body (json/write-str {:email "[email protected]" :username "a"})})))