Sha256: b546173e760e5ab300b761b9397794d2ccd3ac01a59c56f2f7cc93d5ee175fd2

Contents?: true

Size: 948 Bytes

Versions: 12

Compression:

Stored size: 948 Bytes

Contents

module ElocalApiSupport
  class Authorization::DefaultAuthorizer
    attr_reader :caller

    FAIL_MESSAGE = <<-EOL.strip
  No token could be found for ElocalApiSupport to use.  Please resolve this by either
    - Define a method required_token which provides a token to check
    - Set the configuration token in your config/application.rb by setting a value for config.elocal_api_support_token
    - Define a method authorizer return a custom Authorization object which responds to authorize(token)
    EOL

    def initialize(caller)
      @caller = caller
    end

    def authorize(token)
      find_required_token == token
    end

    def find_required_token
      if caller.respond_to?(:required_token, true)
        caller.send(:required_token)
      elsif Rails.application.config.elocal_api_support_token.present?
        Rails.application.config.elocal_api_support_token
      else
        fail FAIL_MESSAGE
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
elocal_api_support-1.3.0 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-1.2.0 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-1.1.0 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-1.0.0 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.10 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.9 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.8 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.7 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.5 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.4 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.3 lib/elocal_api_support/default_authorizer.rb
elocal_api_support-0.1.2 lib/elocal_api_support/default_authorizer.rb