gitlab-org--gitlab-foss/app/controllers/jwt_controller.rb

36 lines
1.0 KiB
Ruby
Raw Normal View History

2016-05-02 11:29:17 +00:00
class JwtController < ApplicationController
skip_before_action :authenticate_user!
skip_before_action :verify_authenticity_token
2016-05-13 21:23:02 +00:00
before_action :authenticate_project_or_user
2016-05-02 11:29:17 +00:00
2016-05-02 12:32:16 +00:00
SERVICES = {
2016-05-14 23:23:31 +00:00
Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService,
2016-05-02 12:32:16 +00:00
}
2016-05-02 11:29:17 +00:00
def auth
2016-05-02 12:32:16 +00:00
service = SERVICES[params[:service]]
2016-05-15 00:45:33 +00:00
return head :not_found unless service
2016-05-02 11:29:17 +00:00
@@authentication_result ||= Gitlab::Auth.Result.new
result = service.new(@authentication_result.project, @authentication_result.user, auth_params).
execute(capabilities: @authentication_result.capabilities || [])
2016-05-02 11:29:17 +00:00
2016-05-14 19:04:04 +00:00
render json: result, status: result[:http_status]
2016-05-02 11:29:17 +00:00
end
2016-05-02 12:32:16 +00:00
private
2016-05-02 11:29:17 +00:00
2016-05-13 21:23:02 +00:00
def authenticate_project_or_user
authenticate_with_http_basic do |login, password|
@authentication_result = Gitlab::Auth.find_for_git_client(login, password, ip: request.ip)
2016-05-13 21:23:02 +00:00
2016-09-15 09:57:09 +00:00
render_403 unless @authentication_result.succeeded?
2016-05-13 21:23:02 +00:00
end
end
2016-05-02 12:32:16 +00:00
def auth_params
params.permit(:service, :scope, :account, :client_id)
2016-05-02 11:29:17 +00:00
end
end