2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-04 22:07:49 +00:00
|
|
|
module API
|
|
|
|
# External applications API
|
2020-10-15 00:08:42 +00:00
|
|
|
class Applications < ::API::Base
|
2017-01-04 22:07:49 +00:00
|
|
|
before { authenticated_as_admin! }
|
|
|
|
|
2020-10-28 15:08:49 +00:00
|
|
|
feature_category :authentication_and_authorization
|
|
|
|
|
2017-01-04 22:07:49 +00:00
|
|
|
resource :applications do
|
|
|
|
desc 'Create a new application' do
|
2018-01-23 09:50:10 +00:00
|
|
|
detail 'This feature was introduced in GitLab 10.5'
|
2022-11-07 12:11:44 +00:00
|
|
|
success code: 200, model: Entities::ApplicationWithSecret
|
2017-01-04 22:07:49 +00:00
|
|
|
end
|
|
|
|
params do
|
2022-11-07 12:11:44 +00:00
|
|
|
requires :name, type: String, desc: 'Name of the application.', documentation: { example: 'MyApplication' }
|
|
|
|
requires :redirect_uri, type: String, desc: 'Redirect URI of the application.', documentation: { example: 'https://redirect.uri' }
|
|
|
|
requires :scopes, type: String,
|
|
|
|
desc: 'Scopes of the application. You can specify multiple scopes by separating\
|
|
|
|
each scope using a space',
|
|
|
|
allow_blank: false
|
2020-01-22 18:08:47 +00:00
|
|
|
|
2022-08-11 00:09:45 +00:00
|
|
|
optional :confidential,
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
2022-11-07 12:11:44 +00:00
|
|
|
desc: 'The application is used where the client secret can be kept confidential. Native mobile apps \
|
|
|
|
and Single Page Apps are considered non-confidential. Defaults to true if not supplied'
|
2017-01-04 22:07:49 +00:00
|
|
|
end
|
|
|
|
post do
|
|
|
|
application = Doorkeeper::Application.new(declared_params)
|
|
|
|
|
|
|
|
if application.save
|
2018-01-24 08:44:07 +00:00
|
|
|
present application, with: Entities::ApplicationWithSecret
|
2017-01-04 22:07:49 +00:00
|
|
|
else
|
|
|
|
render_validation_error! application
|
|
|
|
end
|
|
|
|
end
|
2018-10-11 10:54:15 +00:00
|
|
|
|
|
|
|
desc 'Get applications' do
|
2022-11-07 12:11:44 +00:00
|
|
|
detail 'List all registered applications'
|
2018-10-12 09:33:58 +00:00
|
|
|
success Entities::Application
|
2022-11-07 12:11:44 +00:00
|
|
|
is_array true
|
2018-10-11 10:54:15 +00:00
|
|
|
end
|
|
|
|
get do
|
2018-10-15 14:03:08 +00:00
|
|
|
applications = ApplicationsFinder.new.execute
|
2018-10-11 10:54:15 +00:00
|
|
|
present applications, with: Entities::Application
|
|
|
|
end
|
|
|
|
|
2022-11-07 12:11:44 +00:00
|
|
|
desc 'Delete an application' do
|
|
|
|
detail 'Delete a specific application'
|
|
|
|
success code: 204
|
|
|
|
end
|
2022-10-05 21:09:08 +00:00
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'The ID of the application (not the application_id)'
|
|
|
|
end
|
2018-10-11 10:54:15 +00:00
|
|
|
delete ':id' do
|
2018-10-15 14:03:08 +00:00
|
|
|
application = ApplicationsFinder.new(params).execute
|
2021-03-16 18:11:53 +00:00
|
|
|
break not_found!('Application') unless application
|
|
|
|
|
2018-10-15 14:03:08 +00:00
|
|
|
application.destroy
|
2018-10-11 10:54:15 +00:00
|
|
|
|
2020-01-16 18:08:46 +00:00
|
|
|
no_content!
|
2018-10-11 10:54:15 +00:00
|
|
|
end
|
2017-01-04 22:07:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|