authn.handler
Ring request handlers for login and logout.
Provides ready-to-use Ring handlers for common authentication operations. These handlers accept JSON request bodies and return JSON responses.
login-handler
(login-handler authenticator)Ring handler for login requests.
Accepts a POST request with JSON body containing credentials. The structure of the credentials depends on your CredentialValidator implementation.
Common examples: - {"username": "user", "password": "pass"} - Username/password - {"api-key": "key"} - API key authentication - {"access-token": "token"} - Token-based authentication
On success, returns 200 with session information and sets a session cookie. On failure, returns 401 with error message.
Example:
(defn routes [authenticator]
[["POST" "/login" (login-handler authenticator)]])
logout-handler
(logout-handler authenticator)Ring handler for logout requests.
Accepts a POST request. Reads the session cookie, destroys the session, and clears the session cookie. Returns 200 on success.
Example:
(defn routes [authenticator]
[["POST" "/logout" (logout-handler authenticator)]])
whoami-handler
(whoami-handler)Ring handler that returns current user information.
Accepts a GET request. Returns the authenticated user’s information if authenticated, or 401 if not authenticated.
This handler should be used after the authentication middleware has been applied.
Example:
(defn routes [authenticator]
[["GET" "/whoami" (whoami-handler)]])