Skip to content

Instantly share code, notes, and snippets.

@stim371
Last active December 22, 2015 13:39
Show Gist options
  • Save stim371/6480808 to your computer and use it in GitHub Desktop.
Save stim371/6480808 to your computer and use it in GitHub Desktop.
adding error logging to the devise_oauth2_providable gem
require 'devise/strategies/base'
# in order to diagnose issues with the iphone app, we needed
# to monkeypatch the error code to put the error explanation in the logs
module Devise
module Strategies
class Oauth2GrantTypeStrategy < Authenticatable
# return custom error response in accordance with the oauth spec
# see http://tools.ietf.org/html/draft-ietf-oauth-v2-16#section-4.3
def oauth_error!(error_code = :invalid_request, description = nil)
body = {:error => error_code}
body[:error_description] = description if description
push_error_to_console(body)
custom! [400, {'Content-Type' => 'application/json'}, [body.to_json]]
throw :warden
end
def push_error_to_console(body)
p "*** devise oauth error 400 with body: #{body}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment