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

authorization in Web Services #50

Closed
danicuki opened this issue Apr 6, 2010 · 3 comments
Closed

authorization in Web Services #50

danicuki opened this issue Apr 6, 2010 · 3 comments

Comments

@danicuki
Copy link

danicuki commented Apr 6, 2010

Do you think is a good idea to return status code 403 when something is not authorized? I think this should be specially important when using cancan for Web Services authorization. And in that case, what kind of response should be rendered to the Web Service (for example, on a .xml request)?

@ryanb
Copy link
Owner

ryanb commented Apr 15, 2010

You can handle this in the rescue_from method in the application. Perhaps like this.

rescue_from CanCan::AccessDenied do |exception|
  respond_to do |format|
    format.html { redirect_to root_url }
    format.xml { render :xml => "...", :status => 403 }
  end
end

I'll look into this more and add some documentation to the wiki. Thanks for reporting this.

@danicuki
Copy link
Author

I did it in another way. I've overrided the unauthorized! method in ApplicationController

def unauthorized!
    render :template => 'layouts/unauthorized', :status => :forbidden
end

@ryanb
Copy link
Owner

ryanb commented Apr 17, 2010

Here is a link to the wiki page for this topic.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants