debian-mirror-gitlab/app/controllers/jwt_controller.rb

46 lines
1.5 KiB
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class JwtController < ApplicationController
skip_before_action :authenticate_user!
skip_before_action :verify_authenticity_token
before_action :authenticate_project_or_user
SERVICES = {
Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService,
}
def auth
service = SERVICES[params[:service]]
return head :not_found unless service
2016-09-29 09:46:39 +05:30
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params).
execute(authentication_abilities: @authentication_result.authentication_abilities || [])
2016-06-02 11:05:42 +05:30
render json: result, status: result[:http_status]
end
private
def authenticate_project_or_user
2016-09-29 09:46:39 +05:30
@authentication_result = Gitlab::Auth::Result.new
2016-06-02 11:05:42 +05:30
2016-09-29 09:46:39 +05:30
authenticate_with_http_basic do |login, password|
@authentication_result = Gitlab::Auth.find_for_git_client(login, password, project: nil, ip: request.ip)
2016-06-02 11:05:42 +05:30
2016-09-29 09:46:39 +05:30
render_403 unless @authentication_result.success? &&
(@authentication_result.actor.nil? || @authentication_result.actor.is_a?(User))
2016-06-02 11:05:42 +05:30
end
2016-09-29 09:46:39 +05:30
rescue Gitlab::Auth::MissingPersonalTokenError
render_missing_personal_token
2016-06-02 11:05:42 +05:30
end
2016-09-29 09:46:39 +05:30
def render_missing_personal_token
render plain: "HTTP Basic: Access denied\n" \
"You have 2FA enabled, please use a personal access token for Git over HTTP.\n" \
"You can generate one at #{profile_personal_access_tokens_url}",
status: 401
2016-06-02 11:05:42 +05:30
end
2016-09-29 09:46:39 +05:30
def auth_params
params.permit(:service, :scope, :account, :client_id)
2016-06-02 11:05:42 +05:30
end
end