Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marianoguerra/friend-json-workflow

json auth workflow for cemerick/friend
https://github.com/marianoguerra/friend-json-workflow

Last synced: about 1 month ago
JSON representation

json auth workflow for cemerick/friend

Awesome Lists containing this project

README

        

friend-json-workflow
====================

Adds support for json session workflow to cemerick's `friend library `_

Usage
-----

see clojars page for install instructions:

https://clojars.org/org.marianoguerra/friend-json-workflow

see here for a complete example using `immutant `_:

https://github.com/marianoguerra/immutant-recipes/tree/master/friend-json-auth

the pieces you need to add it to your app are::

(ns myns.api
(:use [ring.middleware params keyword-params nested-params])

(:require
[cemerick.friend :as friend]
(cemerick.friend [credentials :as creds])
[ring.middleware.session :as ring-session]
[marianoguerra.friend-json-workflow :as json-auth]))

(def api-handler (-> my-api
wrap-keyword-params
wrap-nested-params
wrap-params))

(def secure-app (-> api-handler
(friend/authenticate
{:login-uri "/myapp/api/session"
:unauthorized-handler json-auth/unauthorized-handler
:workflows [(json-auth/json-login
:login-uri "/myapp/api/session"
:login-failure-handler json-auth/login-failed
:credential-fn (partial creds/bcrypt-credential-fn logic/get-user-by-username))]})
(ring-session/wrap-session)))

you will have to implement logic/get-user-by-username in the example above

* *POST /myapp/api/session* with a json body with the credentias will do the login
* *DELETE /myapp/api/session* will logout
* *GET /myapp/api/session* will return current credentials

License
-------

Copyright © 2013 marianoguerra

Distributed under the Eclipse Public License, the same as Clojure.