gitlab-org--gitlab-foss/lib/gitlab/auth/request_authenticator.rb

51 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-10-14 00:05:18 +00:00
# Use for authentication only, in particular for Rack::Attack.
# Does not perform authorization of scopes, etc.
module Gitlab
module Auth
class RequestAuthenticator
include AuthFinders
2017-11-07 09:52:05 +00:00
attr_reader :request
2017-10-14 00:05:18 +00:00
def initialize(request)
2017-11-08 18:41:07 +00:00
@request = request
2017-10-14 00:05:18 +00:00
end
def user(request_formats)
request_formats.each do |format|
user = find_sessionless_user(format)
return user if user
end
find_user_from_warden
2017-10-14 00:05:18 +00:00
end
def runner
find_runner_from_token
rescue Gitlab::Auth::AuthenticationError
nil
end
def find_sessionless_user(request_format)
find_user_from_web_access_token(request_format) ||
find_user_from_feed_token(request_format) ||
find_user_from_static_object_token(request_format) ||
find_user_from_basic_auth_job
rescue Gitlab::Auth::AuthenticationError
2017-11-08 18:41:07 +00:00
nil
2017-10-14 00:05:18 +00:00
end
def valid_access_token?(scopes: [])
validate_access_token!(scopes: scopes)
true
rescue Gitlab::Auth::AuthenticationError
false
end
2017-10-14 00:05:18 +00:00
end
end
end