2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# 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
|
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
def user(request_formats)
|
|
|
|
request_formats.each do |format|
|
|
|
|
user = find_sessionless_user(format)
|
|
|
|
|
|
|
|
return user if user
|
|
|
|
end
|
|
|
|
|
|
|
|
find_user_from_warden
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
def find_sessionless_user(request_format)
|
2019-12-04 20:38:33 +05:30
|
|
|
find_user_from_web_access_token(request_format) ||
|
|
|
|
find_user_from_feed_token(request_format) ||
|
|
|
|
find_user_from_static_object_token(request_format)
|
2018-03-17 18:26:18 +05:30
|
|
|
rescue Gitlab::Auth::AuthenticationError
|
|
|
|
nil
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
def valid_access_token?(scopes: [])
|
|
|
|
validate_access_token!(scopes: scopes)
|
|
|
|
|
|
|
|
true
|
|
|
|
rescue Gitlab::Auth::AuthenticationError
|
|
|
|
false
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|