Skip to content

Instantly share code, notes, and snippets.

@scottburton11
Created August 2, 2012 18:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottburton11/3239347 to your computer and use it in GitHub Desktop.
Save scottburton11/3239347 to your computer and use it in GitHub Desktop.
Warden FailureApp for Devise token_authentication
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