Created
August 2, 2012 18:21
-
-
Save scottburton11/3239347 to your computer and use it in GitHub Desktop.
Warden FailureApp for Devise token_authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp::FailureApp < Devise::FailureApp | |
def respond | |
if api_token_failure? | |
invalid_token | |
elsif api_login_failure? | |
invalid_credentials | |
else | |
super | |
end | |
end | |
def invalid_token | |
self.status = 401 | |
self.content_type = request.format.to_s | |
self.response_body = "Access denied, invalid token." | |
end | |
def invalid_credentials | |
self.status = 401 | |
self.content_type = request.format.to_s | |
self.response_body = "Access denied, invalid credentials. To log in, please provide valid :email and :password parameters scoped to the :user parameter key." | |
end | |
def api_token_failure? | |
api_login_failure? && request.params.has_key?("auth_token") | |
end | |
def api_login_failure? | |
request.format == "application/json" && env['warden.options'][:action] == "unauthenticated" | |
end | |
def redirect_url | |
new_user_session_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment