2020-06-16 11:08:32 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module HttpBasicAuthHelpers
|
|
|
|
def user_basic_auth_header(user)
|
|
|
|
access_token = create(:personal_access_token, user: user)
|
|
|
|
|
|
|
|
basic_auth_header(user.username, access_token.token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def job_basic_auth_header(job)
|
2020-08-04 23:10:58 -04:00
|
|
|
basic_auth_header(::Gitlab::Auth::CI_JOB_USER, job.token)
|
2020-06-16 11:08:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def client_basic_auth_header(client)
|
|
|
|
basic_auth_header(client.uid, client.secret)
|
|
|
|
end
|
|
|
|
|
2020-08-13 08:09:50 -04:00
|
|
|
def build_auth_headers(value)
|
|
|
|
{ 'HTTP_AUTHORIZATION' => value }
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_token_auth_header(token)
|
|
|
|
build_auth_headers("Bearer #{token}")
|
|
|
|
end
|
|
|
|
|
2020-06-16 11:08:32 -04:00
|
|
|
def basic_auth_header(username, password)
|
2020-08-13 08:09:50 -04:00
|
|
|
build_auth_headers(ActionController::HttpAuthentication::Basic.encode_credentials(username, password))
|
2020-06-16 11:08:32 -04:00
|
|
|
end
|
|
|
|
end
|