Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store session for api_key auth #3207 #3208

Merged
merged 3 commits into from
Apr 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,18 @@ def current_user
# - Else: the first session found at request.session that comes from warden
def current_viewer
if @current_viewer.nil?
authenticated_usernames = request.session.select {|k,v| k.start_with?("warden.user")}.values
current_user_present = authenticated_usernames.select { |username|
CartoDB.extract_subdomain(request) == username
}.first

if current_user_present.nil?
authenticated_username = authenticated_usernames.first
@current_viewer = authenticated_username.nil? ? nil : User.where(username: authenticated_username).first
else
if current_user && env["warden"].authenticated?(current_user.username)
@current_viewer = current_user
else
authenticated_usernames = request.session.select {|k,v| k.start_with?("warden.user")}.values
current_user_present = authenticated_usernames.select { |username|
CartoDB.extract_subdomain(request) == username
}.first

if current_user_present.nil?
authenticated_username = authenticated_usernames.first
@current_viewer = authenticated_username.nil? ? nil : User.where(username: authenticated_username).first
end
end
end
@current_viewer
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def valid?
params[:api_key].present?
end

# We don't want to store a session and send a response cookie
def store?
false
end

def authenticate!
begin
if (api_key = params[:api_key]) && api_key.present?
Expand Down