Skip to content

Authentication

Sebastian edited this page Mar 1, 2017 · 4 revisions

To authenticate your url with Facebook, a request is sent to the url you provide which sends a verify_token and a challenge. The endpoint needs to return the challenge back to the client to pass.

fb-messenger has a helper to extract the challenge from a map representing the request and return it: authenticate.

Usage of authenticate

The function authenticate takes both the params from the request and the token which was set within the setup process with facebook. It checks the params and returns either nil if something does not match or the challenge string which needs to be returned to the client.

It can be used with any http library. As an example, take the function to handle a request with compojure:

(defn bot-authenticate [{:keys [params]}]
  (fb-messenger.auth/authenticate "my-token" params))

(def bot-routes
  (GET "/" request (bot-authenticate request)))

If you want to set the token and not pass it with every request:

(fb-messenger.auth/set-token "my-token")

(defn bot-authenticate [{:keys [params]}]
  (fb-messenger.auth/authenticate params))