debian-mirror-gitlab/app/controllers/concerns/sessionless_authentication.rb

39 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-29 20:51:05 +05:30
# frozen_string_literal: true
# == SessionlessAuthentication
#
2019-12-04 20:38:33 +05:30
# Controller concern to handle PAT, RSS, and static objects token authentication methods
2018-11-29 20:51:05 +05:30
#
module SessionlessAuthentication
2019-12-21 20:55:43 +05:30
extend ActiveSupport::Concern
included do
before_action :enable_admin_mode!, if: :sessionless_user?
end
2019-12-04 20:38:33 +05:30
# This filter handles personal access tokens, atom requests with rss tokens, and static object tokens
2018-11-29 20:51:05 +05:30
def authenticate_sessionless_user!(request_format)
user = Gitlab::Auth::RequestAuthenticator.new(request).find_sessionless_user(request_format)
sessionless_sign_in(user) if user
end
def sessionless_user?
2019-10-12 21:52:04 +05:30
current_user && !session.key?('warden.user.user.key')
2018-11-29 20:51:05 +05:30
end
def sessionless_sign_in(user)
if user && can?(user, :log_in)
# Notice we are passing store false, so the user is not
# actually stored in the session and a token is needed
# for every request. If you want the token to work as a
# sign in token, you can simply remove store: false.
sign_in(user, store: false, message: :sessionless_sign_in)
end
end
2019-12-21 20:55:43 +05:30
def enable_admin_mode!
current_user_mode.enable_admin_mode!(skip_password_validation: true) if Feature.enabled?(:user_mode_in_session)
end
2018-11-29 20:51:05 +05:30
end