Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:46:57+00:00 2026-05-28T19:46:57+00:00

I am trying to implement a service with a public api which access control

  • 0

I am trying to implement a service with a public api which access control pattern is very similar to facebooks graph api. I am using the doorkeeper gem that allows me to do OAuth with Devise and also easily give permissions/scopes to access tokens.

So beyond that, I would need:
– access control based on the scope of the access token
– access control for different groups users on the platform (like privacy settings on facebook)
– access control has to be dynamic, cant assume fixed roles

No I did take a look at CanCan which seems to do role based access control, but it doesnt seem to incoorperate OAuth very easily, so that I ask myself whether it might be the best to just roll out my own system? Would it be the right way to basically do all the access control on the models then?

Do you have any other suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:46:59+00:00Added an answer on May 28, 2026 at 7:46 pm

    I think CanCan can handle what you want. Since you haven’t provided specifics on what deems a user authorized, I will show you some methods I think will be helpful. The first thing I will say is that you can pass in any objects you want to your ability file. To do so, you do the following:

    def ApplicationController < ActionController::Base
      def current_ability
        @current_ability = CustomAbility.new(pass, in, anything, here)
      end
    end
    

    In app/models you would when define custom_ability.rb:

    def CustomAbility 
      include CanCan::Ability
    
      def initialize(anything, you, want, here)
        ...
      end
    end
    

    In this case, anything = pass, you = in, want = anything, here = here. In addition, you can call some methods on the resource you are authorizing. CanCan works by loading @resource_name and then entering the ability file to authorize. It loads @resource_name by assuming RESTful routes, but you can easily use a before_filter to load your own resource, as long as you store it in @resource_name (i.e. store a User in @user).

    You can also call certain methods on the object you are authorizing already created parameters. For instance, you may want to do something like this:

    def initialize(user)
      can :read, Post do |post|
        !((post.readable_groups & user.groups).empty?)
      end
    end
    

    Basically, if a line in that block returns false then you become unauthorized. The only caveat is that the block is not executed on create or new. There are ways around this. For instance, lets say you enforced one post per user in the model level with uniqueness validations. You could use a before filter to load the post setting the user_id, and then do

    can :create, Post, valid?: true
    

    Anyway, hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we are trying to implement an application using the Service Layer Pattern cause our
I'm trying to implement a REST service using WCF which will take the parameters
I'm trying to implement a stateful web service in PHP using the SOAP extension.
It's just a service locater type of pattern I am trying to implement, where
I am trying to fetch URLs using Google App Engine's urlFetch service and implement
I'm trying to implement a service contract that contains a method which takes a
I am trying to implement a very simple service example. The user inputs the
I'm trying to implement a view tracking web service on my website. I'm using
I am trying to implement a remote REST service which is used to handle
I'm trying to implement an HTML Parsing web service as described in Chapter 23

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.