summaryrefslogtreecommitdiff
path: root/lib/gitlab/auth/request_authenticator.rb
blob: 46ec040ce9246c09636d455f8bce4511c36468cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Use for authentication only, in particular for Rack::Attack.
# Does not perform authorization of scopes, etc.
module Gitlab
  module Auth
    class RequestAuthenticator
      include UserAuthFinders

      attr_reader :request

      def initialize(request)
        @request = request
      end

      def user
        find_sessionless_user || find_user_from_warden
      end

      def find_sessionless_user
        find_user_from_access_token || find_user_from_rss_token
      rescue Gitlab::Auth::AuthenticationError
        nil
      end
    end
  end
end