The Keycloak Environment For Clojure

ngrok

ngrok will allow us to access Keycloak from this notebook.

curl -sS https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip
unzip /ngrok.zip
3.7s

Settings for the ngrok configuration file. The addr setting forwards traffic to the local port number or network address. It is set to 8080. Make sure the Keycloak default ports are free:

region: us
console_ui: true
tunnels:
  btf:
    proto: http
    addr: 8080
    subdomain: btf
YAML

Grab your authtoken from ngrok, store the token in your Nextjournal secret vault, and add it to the environment. The token will authenticate this notebook with the ngrok service.

Prepend the authtoken to the configuration file above, ngrok.yml.

echo 'authtoken:' $ngrok | cat - ngrok.yml > /tmp/out && mv /tmp/out ngrok.yml
0.8s

Run ngrok in the background using nohup. Unfortunately, there are no plans to offer a daemon service in the basic ngrok package.

nohup /ngrok start --all --config="/ngrok.yml" &> /tmp/ngrok.log & sleep 1
tail /tmp/ngrok.log
1.9s

Place the URL into a browser and the tunnel will be visible. Anything served from port 8080 will appear here.

Keycloak

curl -LO https://github.com/keycloak/keycloak/releases/download/15.0.1/keycloak-15.0.1.zip && unzip keycloak-15.0.1.zip 
12.0s

Start keycloak with keycloak’s bin/standalone.sh. This runs on port 8080, make sure it is available on your machine.

nohup /keycloak-15.0.1/bin/standalone.sh &> /tmp/keycloak.log & sleep 1
tail /tmp/keycloak.log
1.9s

Keycloak needs a default admin user as a basis. Create the admin user. I found out the hard way that keycloak is reserved.

keycloak-15.0.1/bin/add-user-keycloak.sh -r master -u nextjournal -p nextjournal > /tmp/add-user-keycloak.txt
12.8s

Administration

Open http://btf.ngrok.io/auth/. The getting started tutorial on Keycloak's official website gives detailed instructions on how to use the admin console.

To stop the ngrok tunnel or Keycloak process, use the kill command with the process ID: kill <PID> or kill -9 "$(pgrep ngrok)".

ps aux
1.4s

Appendix

{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
        ;; complient is used for autocompletion
        ;; add your libs here (and restart the runtime to pick up changes)
        compliment/compliment {:mvn/version "0.3.9"}}}
Extensible Data Notation
Runtimes (1)