This repo provides a lib for interacting with NuID APIs within Clojure applications.
Read the latest lib docs or checkout the NuID platform docs for API docs, guides, video tutorials, and more.
nuid/sdk {:mvn/version "0.3.0"}
;; or
nuid/sdk {:git/url "https://github.com/NuID/sdk-clojure" :sha "..."}[nuid/sdk "0.3.0"]compile 'nuid:sdk:0.3.0'<dependency>
<groupId>nuid</groupId>
<artifactId>sdk</artifactId>
<version>0.3.0</version>
</dependency>Example ring handler.
For a more detailed example visit the Integrating with NuID guide and the accompanying examples repo.
(ns my.sever.api
(:require
[ring.adapter.jetty :as jetty]
[ring.middleware.cors :as ring.cors]
[nuid.sdk.api.auth :as auth]))
;; ...
(defn register-handler
[{:keys [body-params]}]
(if-let [_ (db/find-by-email (:email body-params))]
(fail-res 400 "Email address already taken")
(let [register-res (auth/credential-create (:credential body-params))
nuid (get-in register-res [:body "nu/id"])
user (when (= 201 (:status register-res))
(-> (select-keys body-params [:email :firstName :lastName])
(assoc :nuid nuid)
(db/user-insert!))
(db/find-by-email (:email body-params)))]
(if user
{:status 201
:body {:user (user->from-db user)}}
(fail-res 400 "Invalid request")))))
;; ...
(defn start-server!
[& args]
;;...
(auth/merge-opts! {::auth/api-key (System/getenv "NUID_AUTH_API_KEY"})
;;...
)You'll need the following dependencies on your system:
- OpenJDK 8
- Clojure 1.10
- NodeJS 12 (with npm)
You can invoke the tests using make test. On your first run you'll be prompted
for the Auth API Host and Key.
Bug reports and pull requests are welcome on GitHub at https://github.com/NuID/sdk-clojure.
The gem is available as open source under the terms of the MIT License.