Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

configurable attribute

  • Loading branch information...
commit c6aacca7839e1ee4fad8b4e3dd448a3eab04277e 1 parent 4a2b302
@saturnflyer authored
View
12 HELP_admin.markdown
@@ -1,11 +1,13 @@
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 specified and will allow or disallow based on a user in Radiant having the same value in the given attribute.
-This requires that you manage your user accounts so that all active users have valid email addresses listed in the Radiant database.
+This requires that you manage your user accounts so that all active users have valid information listed in the Radiant database.
-If you would like to change the Header used to authorize users from a rake task you may run
+If you would like to change the Header or Attribute used to authorize users from a rake task you may run
- rake radiant:extensions:header_authorize:set HEADER='AUTHORIZED_USER'
+ rake radiant:extensions:header_authorize:set HEADER='AUTHORIZED_USER' ATTRIBUTE='login'
-Built by Saturn Flyer http://www.saturnflyer.com
+Built by Saturn Flyer
+
+[http://www.saturnflyer.com](http://www.saturnflyer.com)
View
4 README
@@ -2,9 +2,9 @@
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 <code>authenticate_with_header</code> method is added as a before_filter on the ApplicationController. <code>authenticate_with_header<code> will look for a header specified and will allow or disallow based on a user in Radiant having the same value in the given attribute.
-This requires that you manage your user accounts so that all active users have valid email addresses listed in the Radiant database.
+This requires that you manage your user accounts so that all active users have valid information listed in the Radiant database.
See HELP_admin.markdown for more details.
View
11 header_authorize_extension.rb
@@ -1,5 +1,6 @@
require_dependency 'application'
HEADER_AUTHORIZE_KEY = 'authorization.header'
+HEADER_AUTHORIZE_ATTR = 'authorization.attribute'
class HeaderAuthorizeExtension < Radiant::Extension
version "1.0"
@@ -14,9 +15,17 @@ def activate
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."
+ auth_config.update_attribute :description, "This header will be used to authenticate users against this application's database. You'll need to restart for changes to take effect."
end
end
+ if Radiant::Config[HEADER_AUTHORIZE_ATTR].blank?
+ Radiant::Config[HEADER_AUTHORIZE_ATTR] = 'email'
+ auth_config = Radiant::Config.find_by_key(HEADER_AUTHORIZE_ATTR)
+ if auth_config.respond_to?(:description)
+ auth_config.update_attribute :description, "This attrubite on the user record will be used to authenticate against the HTTP header. You'll need to restart for changes to take effect."
+ end
+ end
+
end
end
View
12 lib/header_authorization.rb
@@ -11,18 +11,22 @@ def self.append_features(base)
def authenticate_with_header
unless self.current_user
- if !headers[auth_config].blank?
- self.current_user = User.find_by_email(headers[auth_config])
+ if !headers[auth_header].blank?
+ self.current_user = User.send("find_by_#{auth_attr}",headers[auth_header])
end
end
end
- def auth_config
+ def auth_header
Radiant::Config[HEADER_AUTHORIZE_KEY].downcase.to_sym || :user_email
end
+ def auth_attr
+ Radiant::Config[HEADER_AUTHORIZE_ATTR].downcase || 'email'
+ end
+
# Stub out header
def stubbed_header_for_development
- headers[auth_config] = 'tester@test.com' if RAILS_ENV == 'development'
+ headers[auth_header] = 'tester@test.com' if RAILS_ENV == 'development'
end
end
View
9 lib/tasks/header_authorize_tasks.rake
@@ -2,12 +2,13 @@ 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'"
+ desc "Sets the 'authorization.header' and 'authorization.attribute' in Radiant::Config to the strings passed in with HEADER='AUTHORIZED_USER' and ATTRIBUTE='email'"
task :set => :environment do
- if ENV['HEADER'].nil?
- puts "You must provide a HEADER, such as HEADER='AUTHORIZED_USER'"
+ if ENV['HEADER'].nil? && ENV['ATTRIBUTE'].nil?
+ puts "You must provide a HEADER or ATTRIBUTE, such as HEADER='AUTHORIZED_USER' ATTRIBUTE='email'"
else
- Radiant::Config[HEADER_AUTHORIZE_KEY] = "#{ENV['HEADER']}"
+ Radiant::Config[HEADER_AUTHORIZE_KEY] = "#{ENV['HEADER']}" if ENV['HEADER']
+ Radiant::Config[HEADER_AUTHORIZE_ATTR] = "#{ENV['ATTRIBUTE']}" if ENV['ATTRIBUTE']
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.