mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
add revocation ctl
This commit is contained in:
parent
cc19ab2bb0
commit
2ebe149872
2 changed files with 33 additions and 0 deletions
32
app/controllers/api/revocations_controller.rb
Normal file
32
app/controllers/api/revocations_controller.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
class API::RevocationsController < ActionController::API
|
||||
def create
|
||||
a = request.headers["authorization"]
|
||||
return head 401 unless a.present? && ActiveSupport::SecurityUtils.secure_compare(a, Rails.application.credentials.revoker_key)
|
||||
t = params[:token]
|
||||
return head 400 unless t.present?
|
||||
|
||||
public_api_key = Public::APIKey.accessible.find_by(token: t)
|
||||
|
||||
if public_api_key.present?
|
||||
user = public_api_key.public_user
|
||||
return render json: {
|
||||
success: true,
|
||||
owner_email: user.email
|
||||
}
|
||||
end
|
||||
|
||||
internal_api_key = APIKey.accessible.find_by(token: t)
|
||||
|
||||
if internal_api_key.present?
|
||||
user = internal_api_key.user
|
||||
return render json: {
|
||||
success: true,
|
||||
owner_email: user.email
|
||||
}
|
||||
end
|
||||
|
||||
render json: {
|
||||
success: false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -645,6 +645,7 @@ Rails.application.routes.draw do
|
|||
|
||||
scope :api do
|
||||
defaults format: :json do
|
||||
post "revoke", to: "api/revocations#create"
|
||||
namespace :public do
|
||||
scope "", module: :api do
|
||||
namespace :v1 do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue