Adds support for api_key authentication

2.0
Fernando Espinosa 12 years ago
parent 93d2bcaa7b
commit a5c0369234

2
.gitignore vendored

@ -1,5 +1,6 @@
.DS_Store
.bundle
dump.rdb
db/*.sqlite3
log/*.log
tmp/*
@ -12,5 +13,6 @@ bin/
config/database.yml
.idea/*
config/app_config.yml
config/redis.conf
src/
spec/support/data/failed_remote/*

@ -1,5 +1,5 @@
web: bundle exec rails server -p $PORT
sql: node ../CartoDB-SQL-API/app.js development
tiler: node ../Windshaft-cartodb/app.js development
redis: redis-server
redis: redis-server config/redis.conf
resque: script/resque

@ -61,7 +61,7 @@ class ApplicationController < ActionController::Base
end
def api_authorization_required
authenticate!(:api_authentication, :scope => request.subdomain)
authenticate!(:api_key, :api_authentication, :scope => request.subdomain)
end
def not_authorized

@ -50,6 +50,32 @@ Warden::Strategies.add(:api_authentication) do
end
end
Warden::Strategies.add(:api_key) do
def valid?
params[:api_key].present?
end
def authenticate!
begin
if (api_key = params[:api_key]) && api_key.present?
user_name = request.subdomain
if $users_metadata.SISMEMBER "rails:users:#{user_name}:map_key", api_key
user_id = $users_metadata.HGET "rails:users:#{user_name}", 'id'
return fail! if user_id.blank?
user = User[user_id]
success!(user)
else
fail!
end
else
fail!
end
rescue
fail!
end
end
end
Warden::Manager.after_authentication do |user,auth,opts|
user.set_map_key
end

Loading…
Cancel
Save