feature(api): add ensure_authorized_network for api_controller v1 and v2
This commit is contained in:
parent
6e5678d1c2
commit
d8bc38bc69
4 changed files with 103 additions and 0 deletions
|
@ -2,6 +2,7 @@ class API::V2::BaseController < ApplicationController
|
|||
skip_forgery_protection if: -> { request.headers.key?('HTTP_AUTHORIZATION') }
|
||||
skip_before_action :setup_tracking
|
||||
before_action :authenticate_from_token
|
||||
before_action :ensure_authorized_network, if: -> { @api_token.present? }
|
||||
|
||||
before_action do
|
||||
Current.browser = 'api'
|
||||
|
@ -46,4 +47,11 @@ class API::V2::BaseController < ApplicationController
|
|||
Current.user = @current_user
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_authorized_network
|
||||
if @api_token.forbidden_network?(request.remote_ip)
|
||||
address = IPAddr.new(request.remote_ip)
|
||||
render json: { errors: ["request issued from a forbidden network. Add #{address.to_string}/#{address.prefix} to your allowed adresses in your /profil"] }, status: :forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue