2022-10-11 01:57:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
class PersonalAccessTokens
|
2022-11-25 23:54:43 +05:30
|
|
|
class SelfInformation < ::API::Base
|
2022-10-11 01:57:18 +05:30
|
|
|
include APIGuard
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
feature_category :system_access
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
helpers ::API::Helpers::PersonalAccessTokensHelpers
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
# As any token regardless of `scope` should be able to view/revoke itself
|
|
|
|
# all available scopes are allowed for this API class.
|
2022-10-11 01:57:18 +05:30
|
|
|
# Please be aware of the permissive scope when adding new endpoints to this class.
|
|
|
|
allow_access_with_scope(Gitlab::Auth.all_available_scopes)
|
|
|
|
|
|
|
|
before { authenticate! }
|
|
|
|
|
|
|
|
resource :personal_access_tokens do
|
2023-01-13 00:05:48 +05:30
|
|
|
desc "Get single personal access token" do
|
|
|
|
detail 'Get the details of a personal access token by passing it to the API in a header'
|
|
|
|
success code: 200, model: Entities::PersonalAccessToken
|
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[personal_access_tokens]
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
get 'self' do
|
|
|
|
present access_token, with: Entities::PersonalAccessToken
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc "Revoke a personal access token" do
|
|
|
|
detail 'Revoke a personal access token by passing it to the API in a header'
|
|
|
|
success code: 204
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad Request' }
|
|
|
|
]
|
|
|
|
tags %w[personal_access_tokens]
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
delete 'self' do
|
|
|
|
revoke_token(access_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|