Sha256: 7e01b2aab98398634d551ccf1f83adc962ed9a29afbdb74ea5ffe204735e646f

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

module Rack
  module OAuth2
    module Server
      class Error
        module Resource

          DEFAULT_DESCRIPTION = {
            :invalid_request => "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.",
            :invalid_token => "The access token provided is invalid.",
            :expired_token => "The access token provided has expired.",
            :insufficient_scope => "The request requires higher privileges than provided by the access token."
          }

          def error!(error, description = nil, options = {})
            description ||= DEFAULT_DESCRIPTION[error]
            options[:realm] = realm
            exception = case error
            when :invalid_token, :expired_token
              Unauthorized
            when :insufficient_scope
              Forbidden
            when :invalid_request
              BadRequest
            else
              raise Error.new(options[:status] || 400, error, description, options)
            end
            raise exception.new(error, description, options)
          end

          def invalid_request!(description = nil, options = {})
            error!(:invalid_request, description, options)
          end
      
          def invalid_token!(description = nil, options = {})
            error!(:invalid_token, description, options)
          end

          def expired_token!(description = nil, options = {})
            error!(:expired_token, description, options)
          end

          def insufficient_scope!(description = nil, options = {})
            error!(:insufficient_scope, description, options)
          end

        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-oauth2-0.2.1 lib/rack/oauth2/server/error/resource.rb
rack-oauth2-0.2.0 lib/rack/oauth2/server/error/resource.rb