blob: 32a98908e5bcf7b89f36518cd65ad1d6b8c187c6 (
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
26
27
28
29
30
31
32
33
34
35
36
37
|
# frozen_string_literal: true
module Gitlab
module APIAuthentication
class TokenLocator
UsernameAndPassword = Struct.new(:username, :password)
include ActiveModel::Validations
include ActionController::HttpAuthentication::Basic
attr_reader :location
validates :location, inclusion: { in: %i[http_basic_auth] }
def initialize(location)
@location = location
validate!
end
def extract(request)
case @location
when :http_basic_auth
extract_from_http_basic_auth request
end
end
private
def extract_from_http_basic_auth(request)
username, password = user_name_and_password(request)
return unless username.present? && password.present?
UsernameAndPassword.new(username, password)
end
end
end
end
|