Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Dynamic user roles #55

Merged
merged 1 commit into from Mar 29, 2013
Merged

Dynamic user roles #55

merged 1 commit into from Mar 29, 2013

Conversation

lynaghk
Copy link
Contributor

@lynaghk lynaghk commented Mar 25, 2013

Allow :roles to be a function, which will be executed with no args and assumed to return a collection of roles each time user authorizations are checked.

This allows, e.g., promoting a user to a new role without forcing a logout+login.

Closes #21.

…d assumed to return a collection of roles each time user authorizations are checked.

This allows, e.g., promoting a user to a new role without forcing a logout+login.

Closes cemerick#21.
@lynaghk
Copy link
Contributor Author

lynaghk commented Mar 26, 2013

Actually, I'd like to split out the roles accessor into its own function:

(defn roles [identity]
  (let [granted-roles (-> identity current-authentication :roles)]
    (if (fn? granted-roles)
      (granted-roles)
      granted-roles)))

I'd like to dispatch against a user's roles manually.
E.g., if the user has the "free-user" role and tries to access the "/paid-content" context, I can redirect him or her to "/buy" in the unauthorized handler.

Or is that approach asking for trouble?

@lynaghk
Copy link
Contributor Author

lynaghk commented Mar 28, 2013

Re: our in-person conversation, handling the dispatch against user-roles manually sounds good, so disregard the previous comment.

For Internet posterity, here's what that'd look like:

(if (friend/authorized? #{::db/member} (friend/identity req))
  (members-handler req)
  (redirect "/buy"))

@cemerick cemerick merged commit 683bacc into cemerick:master Mar 29, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

:roles for authorization are static from authentication time
2 participants