ring-discord-auth
provides functions to verify ED-25519 signatures sent by Discord when using webhook-based interactions.
This does not provide support for Discord's OAuth2.
This library uses caesium, a cryptography library for Clojure. This library requires the presence of libsodium version 1.0.18 or higher, a native library, so make sure to install that in your compilation/execution environment.
Quick ways to install libsodium:
sudo apt update && sudo apt install libsodium-dev
pacman -S libsodium
Check the libsodium site for official installation info and other systems like Windows.
Then, you can add the library through the dependency below.
Below is an example of a minimal Discord app that uses the library. Here, a synchronous handler is used, but the middleware also supports asynchronous handlers.
(ns example.core
(:gen-class)
(:require [ring-discord-auth.core :refer [wrap-authenticate]]
[ring.middleware.json :refer [wrap-json-body wrap-json-response]]
[ring.util.response :refer [response]]
[org.http-kit.server :as http]))
(defn handler [{{:keys [type]} :body :as _request}]
(response
(case type
1 {:type 1} ; Respond to PING with PONG
2 {:type 4 :data {:content "Hello!"}} ; Respond to a slash command with "Hello!"
3 {:type 6}))) ; ACK component presses but do nothing further
(def public-key "Your app's public key (can be found in the developer portal)")
(defn -main [& args]
(http/run-server
(-> handler
wrap-json-response
(wrap-json-body {:keywords? true})
(wrap-authenticate public-key))))
Note that wrap-authenticate
requires access to the raw, unmodified body and must therefore be run before wrap-json-body
.
Copyright © 2021 JohnnyJayJay
This program and the accompanying materials are made available under the terms of the MIT License which is available at https://mit-license.org/.
Can you improve this documentation? These fine people already did:
JohnnyJayJay & JohnnyEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close