Skip to content
Browse files

Notes about CanCan

  • Loading branch information...
1 parent 88ecf42 commit 5c710c2ddeadf15f03b2d6390924c4b2582aaabf @yury yury committed
Showing with 35 additions and 0 deletions.
  1. +35 −0 README.md
View
35 README.md
@@ -41,5 +41,40 @@ Create migration [TODO: write generator]
look at `db/migrate/20120622164619_devise_create_oauth.rb` for now
+## CanCan support
+
+if your app is accessed with `access_token` then we set it as `oauth_token` to current_user
+
+```ruby
+class Ability
+ include CanCan::Ability
+
+ def initialize(user)
+ user ||= User.new # guest user (not logged in)
+ if user.oauth_token?
+ # has access_token, so we set access rights with scope
+ setup_client(user)
+ else
+ # normal user access rights setup
+ setup(user)
+ end
+
+ # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
+ end
+
+ private
+
+ def setup_client(user)
+ if user.oauth_scope? :write
+ can :create, :protected_resource
+ end
+ end
+
+ def setup(user)
+
+ end
+end
+```
+
This project rocks and uses MIT-LICENSE.

0 comments on commit 5c710c2

Please sign in to comment.
Something went wrong with that request. Please try again.