2016-05-02 07:29:17 -04:00
|
|
|
class JwtController < ApplicationController
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
skip_before_action :verify_authenticity_token
|
2016-05-13 17:23:02 -04:00
|
|
|
before_action :authenticate_project_or_user
|
2016-05-02 07:29:17 -04:00
|
|
|
|
2016-05-02 08:32:16 -04:00
|
|
|
SERVICES = {
|
2016-05-14 19:23:31 -04:00
|
|
|
Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService,
|
2016-05-02 08:32:16 -04:00
|
|
|
}
|
|
|
|
|
2016-05-02 07:29:17 -04:00
|
|
|
def auth
|
2016-05-02 08:32:16 -04:00
|
|
|
service = SERVICES[params[:service]]
|
2016-05-14 20:45:33 -04:00
|
|
|
return head :not_found unless service
|
2016-05-02 07:29:17 -04:00
|
|
|
|
2016-09-13 09:27:05 -04:00
|
|
|
result = service.new(@project, @user, auth_params).execute(capabilities: @capabilities)
|
2016-05-02 07:29:17 -04:00
|
|
|
|
2016-05-14 15:04:04 -04:00
|
|
|
render json: result, status: result[:http_status]
|
2016-05-02 07:29:17 -04:00
|
|
|
end
|
|
|
|
|
2016-05-02 08:32:16 -04:00
|
|
|
private
|
2016-05-02 07:29:17 -04:00
|
|
|
|
2016-05-13 17:23:02 -04:00
|
|
|
def authenticate_project_or_user
|
|
|
|
authenticate_with_http_basic do |login, password|
|
2016-09-13 09:27:05 -04:00
|
|
|
@auth_result = Gitlab::Auth.find_for_git_client(login, password, ip: request.ip)
|
2016-05-13 17:23:02 -04:00
|
|
|
|
2016-09-13 09:27:05 -04:00
|
|
|
@user = auth_result.user
|
|
|
|
@project = auth_result.project
|
|
|
|
@type = auth_result.type
|
|
|
|
@capabilities = auth_result.capabilities || []
|
|
|
|
|
|
|
|
if @user || @project
|
|
|
|
return # Allow access
|
|
|
|
end
|
2016-05-13 17:23:02 -04:00
|
|
|
|
2016-05-14 15:04:04 -04:00
|
|
|
render_403
|
2016-05-13 17:23:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-02 08:32:16 -04:00
|
|
|
def auth_params
|
2016-05-30 10:57:39 -04:00
|
|
|
params.permit(:service, :scope, :account, :client_id)
|
2016-05-02 07:29:17 -04:00
|
|
|
end
|
|
|
|
end
|