Skip to content

Commit

Permalink
configurable header
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Jul 24, 2008
1 parent de99a26 commit 4a2b302
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
6 changes: 5 additions & 1 deletion HELP_admin.markdown
@@ -1,7 +1,11 @@
Header Authorize creates alterations of the Login System to accept Header information for authorization. This allows you to use a central authentication system for multiple applications.

An @authenticate_with_header@ method is added as a before_filter on the ApplicationController. @authenticate_with_header@ will look for a header named @user_email@ and will allow or disallow based on a user in Radiant having the given email address.
An `authenticate_with_header` method is added as a before_filter on the ApplicationController. `authenticate_with_header` will look for a header named `user_email` and will allow or disallow based on a user in Radiant having the given email address.

This requires that you manage your user accounts so that all active users have valid email addresses listed in the Radiant database.

If you would like to change the Header used to authorize users from a rake task you may run

rake radiant:extensions:header_authorize:set HEADER='AUTHORIZED_USER'

Built by Saturn Flyer http://www.saturnflyer.com
2 changes: 2 additions & 0 deletions README
Expand Up @@ -6,4 +6,6 @@ An @authenticate_with_header@ method is added as a before_filter on the Applicat

This requires that you manage your user accounts so that all active users have valid email addresses listed in the Radiant database.

See HELP_admin.markdown for more details.

Built by Saturn Flyer http://www.saturnflyer.com
8 changes: 8 additions & 0 deletions header_authorize_extension.rb
@@ -1,4 +1,5 @@
require_dependency 'application'
HEADER_AUTHORIZE_KEY = 'authorization.header'

class HeaderAuthorizeExtension < Radiant::Extension
version "1.0"
Expand All @@ -9,6 +10,13 @@ def activate
ApplicationController.class_eval %{
include HeaderAuthorization
}
if Radiant::Config[HEADER_AUTHORIZE_KEY].blank?
Radiant::Config[HEADER_AUTHORIZE_KEY] = 'USER_EMAIL'
auth_config = Radiant::Config.find_by_key(HEADER_AUTHORIZE_KEY)
if auth_config.respond_to?(:description)
auth_config.update_attribute :description, "This header will be user to authenticate users against this application's database. You'll need to restart for changes to take effect."
end
end
end

end
10 changes: 7 additions & 3 deletions lib/header_authorization.rb
Expand Up @@ -11,14 +11,18 @@ def self.append_features(base)

def authenticate_with_header
unless self.current_user
if !headers[:user_email].blank?
self.current_user = User.find_by_email(headers[:user_email])
if !headers[auth_config].blank?
self.current_user = User.find_by_email(headers[auth_config])
end
end
end

def auth_config
Radiant::Config[HEADER_AUTHORIZE_KEY].downcase.to_sym || :user_email
end

# Stub out header
def stubbed_header_for_development
headers[:user_email] = 'tester@test.com' if RAILS_ENV == 'development'
headers[auth_config] = 'tester@test.com' if RAILS_ENV == 'development'
end
end
16 changes: 16 additions & 0 deletions lib/tasks/header_authorize_tasks.rake
@@ -0,0 +1,16 @@
namespace :radiant do
namespace :extensions do
namespace :header_authorize do

desc "Sets the 'authorization.header' in Radiant::Config to the string passed in with HEADER='AUTHORIZED_USER'"
task :set => :environment do
if ENV['HEADER'].nil?
puts "You must provide a HEADER, such as HEADER='AUTHORIZED_USER'"
else
Radiant::Config[HEADER_AUTHORIZE_KEY] = "#{ENV['HEADER']}"
end
end

end
end
end

0 comments on commit 4a2b302

Please sign in to comment.