NuID Clojure SDK


The Clojure SDK provides an interface for interacting with NuID APIs and utilities. We encourage you to go read the package docs and contact us if you have any questions. We also encourage you to open an issue or pull request if you have any issues or suggestions.

Installation


Install the package from clojars or GitHub. Be sure to add your API Key to your environment configuration.

# my-clj-app/deps.edn
{:deps
 ;; ...
 nuid/sdk {:mvn/version "0.3.0"} ;; check clojars for latest version
 ;; or
 nuid/sdk {:git/url "https://github.com/NuID/sdk-clojure" :sha "..."}}

Usage


To use the package, require it into your app and configure it.

(ns my.sever.api
 (:require [nuid.sdk.api.auth :as auth]))

(defn start-server!
 [& args]
 ;;...
 (auth/merge-opts! {::auth/api-key (System/getenv "NUID_AUTH_API_KEY"})
 ;;...
 )

Once you have a configured sdk client, you can use it to dispatch requests to the API.

(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")))))

You can see a complete code example with ring using the Clojure SDK in our examples repo, or go read our Integrating with NuID guide.