Created
July 22, 2011 18:42
-
-
Save aakashd/1100092 to your computer and use it in GitHub Desktop.
Custom auth header for ActiveResource requests
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
class AppAuthHeaders | |
cattr_accessor :remember_token | |
def self.headers | |
remember_token.blank? ? {"Authorization" => ""} : {"Authorization" => "RememberToken #{self.remember_token}"} | |
end | |
end |
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 File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
Bundler.require(:default, Rails.env) if defined?(Bundler) | |
module MyApp | |
class Application < Rails::Application | |
# some configuration | |
# Custom directories with classes and modules you want to be autoloadable. | |
config.autoload_paths += %W(#{config.root}/app/extensions) | |
# some other configuration | |
end | |
end |
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
module CustomAuthHeader | |
def self.included(klass) | |
class << klass | |
def headers_with_authorization | |
default_headers = headers_without_authorization | |
AppAuthHeaders.headers.keys.each {|key| default_headers.delete(key) } | |
default_headers.reverse_merge!(EngineAuthHeaders.headers) | |
end | |
alias_method_chain :headers, :authorization | |
end | |
end | |
end | |
ActiveResource::Base.send(:include, CustomAuthHeader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment