Last active
December 22, 2015 13:39
-
-
Save stim371/6480808 to your computer and use it in GitHub Desktop.
adding error logging to the devise_oauth2_providable gem
This file contains 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
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