# frozen_string_literal: true require 'drillbit/configuration' require 'drillbit/requests/base' require 'drillbit/accept_header' require 'drillbit/tokens/json_web_token' require 'drillbit/tokens/base64' module Drillbit module Requests class Rails < Base def authorization_token_from_params if request.params.has_key?(JSON_WEB_TOKEN_PARAM_NAME) Tokens::JsonWebToken.__send__( "from_#{Drillbit.configuration.token_type.downcase}", request.params[JSON_WEB_TOKEN_PARAM_NAME] || '', private_key: token_private_key, ) elsif request.params.has_key?(BASE64_TOKEN_PARAM_NAME) Tokens::Base64.convert(raw_token: request.params[BASE64_TOKEN_PARAM_NAME] || '') else Tokens::Null.instance end end private def raw_accept_header_from_header request.headers['Accept'] end def raw_accept_header_from_params request.params['accept'] end def raw_authorization_header request.headers['HTTP_AUTHORIZATION'] || '' end def raw_request_application_name request.headers['X-Application-Name'] end end end end