Sha256: f205d5487e6fe5fa92add905fd792f36f05d653dbde06006b098daae3b1e2deb

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require 'devise/strategies/doorkeeper'
require 'devise/doorkeeper/unconfirmed_resource_response'

module Devise
  module Doorkeeper
    module DoorkeeperFailureApp
      def respond
        if oauth_error?
          invalid_oauth_token
        elsif unconfirmed_resource?
          unconfirmed_resource
        else
          super
        end
      end

      private

      def oauth_error?
        warden_message == Devise::Strategies::Doorkeeper::WARDEN_INVALID_TOKEN_MESSAGE
      end

      def unconfirmed_resource?
        warden_message == Devise::Strategies::Doorkeeper::WARDEN_UNCONFIRMED_RESOURCE_MESSAGE
      end

      def invalid_oauth_token
        error = ::Doorkeeper::OAuth::InvalidTokenResponse.new
        headers.merge! error.headers
        self.response_body = error.body.to_json
        self.status = error.status
      end

      def unconfirmed_resource
        error = UnconfirmedResourceResponse.new
        headers.merge! error.headers
        self.response_body = error.body.to_json
        self.status = error.status
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
devise-doorkeeper-1.2.0.ci.137.1 lib/devise/doorkeeper/doorkeeper_failure_app.rb
devise-doorkeeper-1.2.0 lib/devise/doorkeeper/doorkeeper_failure_app.rb
devise-doorkeeper-1.2.0.ci.133.1 lib/devise/doorkeeper/doorkeeper_failure_app.rb
devise-doorkeeper-1.1.2.ci.129.1 lib/devise/doorkeeper/doorkeeper_failure_app.rb