module ElocalApiSupport::Authorization

Protected Instance Methods

authorize!() click to toggle source
# File lib/elocal_api_support/authorization.rb, line 26
def authorize!
  return if authorized?

  Rails.logger.warn(
    format(
      'Somebody else tried to access our internal API!  Value: %s Params: %s, Headers: %s',
      authorize_request_token,
      params,
      request.headers.map { |k, _v| k }
    )
  )
  render json: error_response_hash, status: 401
end
authorize_request_token() click to toggle source
# File lib/elocal_api_support/authorization.rb, line 40
def authorize_request_token
  [params[:request_token], request.headers['HTTP_X_REQUEST_TOKEN']].detect(&:present?)
end
authorized?() click to toggle source
# File lib/elocal_api_support/authorization.rb, line 10
def authorized?
  find_authorizer.authorize(authorize_request_token)
end
error_response_hash() click to toggle source
# File lib/elocal_api_support/authorization.rb, line 22
def error_response_hash
  { error: 'You are not an authorized user!' }.to_json
end
find_authorizer() click to toggle source
# File lib/elocal_api_support/authorization.rb, line 14
def find_authorizer
  if respond_to?(:authorizer, true)
    send(:authorizer)
  else
    DefaultAuthorizer.new(self)
  end
end