Class: Gitlab::Auth::RequestAuthenticator

Inherits:
Object
  • Object
show all
Includes:
AuthFinders
Defined in:
lib/gitlab/auth/request_authenticator.rb

Constant Summary

Constants included from AuthFinders

AuthFinders::DEPLOY_TOKEN_HEADER, AuthFinders::JOB_TOKEN_HEADER, AuthFinders::JOB_TOKEN_PARAM, AuthFinders::PRIVATE_TOKEN_HEADER, AuthFinders::PRIVATE_TOKEN_PARAM, AuthFinders::RUNNER_JOB_TOKEN_PARAM, AuthFinders::RUNNER_TOKEN_PARAM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthFinders

#cluster_agent_token_from_authorization_token, #deploy_token_from_request, #find_runner_from_token, #find_user_from_access_token, #find_user_from_basic_auth_job, #find_user_from_bearer_token, #find_user_from_feed_token, #find_user_from_job_token, #find_user_from_static_object_token, #find_user_from_warden, #find_user_from_web_access_token, #validate_access_token!

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(request) ⇒ RequestAuthenticator

Returns a new instance of RequestAuthenticator.


12
13
14
# File 'lib/gitlab/auth/request_authenticator.rb', line 12

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request


10
11
12
# File 'lib/gitlab/auth/request_authenticator.rb', line 10

def request
  @request
end

Instance Method Details

#find_sessionless_user(request_format) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/auth/request_authenticator.rb', line 32

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 ||
    find_user_from_job_token
rescue Gitlab::Auth::AuthenticationError
  nil
end

#runnerObject


26
27
28
29
30
# File 'lib/gitlab/auth/request_authenticator.rb', line 26

def runner
  find_runner_from_token
rescue Gitlab::Auth::AuthenticationError
  nil
end

#user(request_formats) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/auth/request_authenticator.rb', line 16

def user(request_formats)
  request_formats.each do |format|
    user = find_sessionless_user(format)

    return user if user
  end

  find_user_from_warden
end

#valid_access_token?(scopes: []) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
45
46
47
48
# File 'lib/gitlab/auth/request_authenticator.rb', line 42

def valid_access_token?(scopes: [])
  validate_access_token!(scopes: scopes)

  true
rescue Gitlab::Auth::AuthenticationError
  false
end