2015-12-21 17:51:49 +01:00
|
|
|
class APIController < ApplicationController
|
2018-03-16 10:10:43 +01:00
|
|
|
before_action :default_format_json
|
2018-03-08 17:41:54 +01:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
protected
|
|
|
|
|
2019-03-06 15:21:25 +01:00
|
|
|
def find_administrateur_for_token(procedure)
|
2022-11-30 10:13:55 +01:00
|
|
|
api_token = APIToken.find_and_verify(authorization_bearer_token, procedure.administrateurs)
|
2023-02-13 14:57:51 +01:00
|
|
|
if api_token.present? && api_token.context.fetch(:procedure_ids).include?(procedure.id)
|
2022-11-30 10:13:55 +01:00
|
|
|
api_token.administrateur
|
2019-02-26 16:18:04 +01:00
|
|
|
end
|
2018-09-26 15:39:45 +02:00
|
|
|
end
|
|
|
|
|
2018-09-26 16:27:58 +02:00
|
|
|
private
|
|
|
|
|
2016-02-19 16:59:18 +01:00
|
|
|
def default_format_json
|
2018-01-11 19:04:39 +01:00
|
|
|
request.format = "json" if !request.params[:format]
|
2016-02-19 16:59:18 +01:00
|
|
|
end
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2022-09-28 12:40:44 +02:00
|
|
|
def authorization_bearer_token
|
2018-09-26 15:39:45 +02:00
|
|
|
params_token.presence || header_token
|
|
|
|
end
|
|
|
|
|
2018-08-24 15:53:57 +02:00
|
|
|
def header_token
|
|
|
|
received_token = nil
|
|
|
|
authenticate_with_http_token do |token, _options|
|
|
|
|
received_token = token
|
|
|
|
end
|
|
|
|
received_token
|
|
|
|
end
|
2018-09-26 15:39:45 +02:00
|
|
|
|
|
|
|
def params_token
|
|
|
|
params[:token]
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|