diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-06-14 00:31:45 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-06-14 00:31:45 +0300 |
commit | 6dbca80c46093443e69f3faace6f1967570b15fa (patch) | |
tree | d3e351e4ed25c347978f33176c729c0495b7de74 /app/controllers/jwt_controller.rb | |
parent | 8c058e8563c287817b81a9a122ceeb5a69f6b221 (diff) | |
parent | 4a8ae77ebac46545fa4811ea60bf53d1e81f10fc (diff) | |
download | gitlab-ce-remove-comment-toggle.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into remove-comment-toggleremove-comment-toggle
Diffstat (limited to 'app/controllers/jwt_controller.rb')
-rw-r--r-- | app/controllers/jwt_controller.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/controllers/jwt_controller.rb b/app/controllers/jwt_controller.rb new file mode 100644 index 00000000000..014b9b43ff2 --- /dev/null +++ b/app/controllers/jwt_controller.rb @@ -0,0 +1,49 @@ +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 + + result = service.new(@project, @user, auth_params).execute + + render json: result, status: result[:http_status] + end + + private + + def authenticate_project_or_user + authenticate_with_http_basic do |login, password| + # if it's possible we first try to authenticate project with login and password + @project = authenticate_project(login, password) + return if @project + + @user = authenticate_user(login, password) + return if @user + + render_403 + end + end + + def auth_params + params.permit(:service, :scope, :account, :client_id) + end + + def authenticate_project(login, password) + if login == 'gitlab-ci-token' + Project.find_by(builds_enabled: true, runners_token: password) + end + end + + def authenticate_user(login, password) + user = Gitlab::Auth.find_with_user_password(login, password) + Gitlab::Auth.rate_limit!(request.ip, success: user.present?, login: login) + user + end +end |