14 #include <restinio/helpers/http_field_parsers/authorization.hpp> 16 #include <restinio/http_headers.hpp> 17 #include <restinio/request_handler.hpp> 18 #include <restinio/expected.hpp> 83 string_view_t result{
"<unknown>" };
87 case extraction_error_t::no_auth_http_field:
88 result = string_view_t{
"no_auth_http_field" };
91 case extraction_error_t::illegal_http_field_value:
92 result = string_view_t{
"illegal_http_field_value" };
95 case extraction_error_t::not_bearer_auth_scheme:
96 result = string_view_t{
"not_bearer_auth_scheme" };
99 case extraction_error_t::invalid_bearer_auth_param:
100 result = string_view_t{
"invalid_bearer_auth_param" };
155 const auto * b64token = std::get_if<authorization_value_t::token68_t>(
156 &http_field.auth_param );
158 return make_unexpected( extraction_error_t::invalid_bearer_auth_param );
160 return params_t{ b64token->value };
217 auto * b64token = std::get_if<authorization_value_t::token68_t>(
218 &http_field.auth_param );
220 return make_unexpected( extraction_error_t::invalid_bearer_auth_param );
222 return params_t{ std::move(b64token->value) };
233 if( !opt_field_value )
234 return make_unexpected( extraction_error_t::no_auth_http_field );
236 auto field_value_parse_result = authorization_value_t::try_parse(
238 if( !field_value_parse_result )
239 return make_unexpected( extraction_error_t::illegal_http_field_value );
241 auto & parsed_value = *field_value_parse_result;
242 if(
"bearer" != parsed_value.auth_scheme )
243 return make_unexpected( extraction_error_t::not_bearer_auth_scheme );
245 return try_extract_params( std::move(parsed_value) );
281 return impl::perform_extraction_attempt(
282 fields.opt_value_of( auth_field_name ) );
305 template<
typename Extra_Data >
346 return impl::perform_extraction_attempt(
347 fields.opt_value_of( auth_field_id ) );
370 template<
typename Extra_Data >
expected_t< std::optional< string_view_t >, not_found_t > find_first(const parameter_with_optional_value_container_t &where, string_view_t what)
A helper function to find the first occurence of a parameter with the specified value.
There is no HTTP field with authentification parameters.
string_view_t to_string_view(extraction_error_t what) noexcept
Helper function to get a string name of extraction_error enum.
std::string token
Access Token.
Parameters for bearer authentification.
expected_t< params_t, extraction_error_t > try_extract_params(const generic_request_t< Extra_Data > &req, http_field_t auth_field_id)
Helper function for getting parameters of bearer authentification from a request. ...
expected_t< params_t, extraction_error_t > try_extract_params(authorization_value_t &&http_field)
Helper function for getting parameters of bearer authentification from an already parsed HTTP-field...
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
expected_t< params_t, extraction_error_t > try_extract_params(const authorization_value_t &http_field)
Helper function for getting parameters of bearer authentification from an already parsed HTTP-field...
The HTTP field with authentification parameters can't be parsed.
expected_t< params_t, extraction_error_t > perform_extraction_attempt(const std::optional< string_view_t > opt_field_value)
expected_t< params_t, extraction_error_t > try_extract_params(const http_header_fields_t &fields, http_field_t auth_field_id)
Helper function for getting parameters of bearer authentification from a set of HTTP-fields.
extraction_error_t
Error codes for failures of extraction of bearer authentification parameters.
Invalid value of parameter for bearer authentification scheme. The single parameter in the form of b6...
Different authentification scheme found. bearer authentification scheme is expected.