2
3
6
7
8
9
10
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>
35
36
37
38
52
53
54
55
56
75
76
77
78
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" };
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
156 &http_field.auth_param );
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
218 &http_field.auth_param );
222 return params_t{ std::move(b64token->value) };
231 const std::optional< string_view_t > opt_field_value )
233 if( !opt_field_value )
236 auto field_value_parse_result = authorization_value_t::try_parse(
238 if( !field_value_parse_result )
241 auto & parsed_value = *field_value_parse_result;
242 if(
"bearer" != parsed_value.auth_scheme )
245 return try_extract_params( std::move(parsed_value) );
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
279 string_view_t auth_field_name )
281 return impl::perform_extraction_attempt(
282 fields.opt_value_of( auth_field_name ) );
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305template<
typename Extra_Data >
313 string_view_t auth_field_name )
315 return try_extract_params( req.header(), auth_field_name );
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
346 return impl::perform_extraction_attempt(
347 fields.opt_value_of( auth_field_id ) );
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370template<
typename Extra_Data >
380 return try_extract_params( req.header(), auth_field_id );
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, string_view_t auth_field_name)
Helper function for getting parameters of bearer authentification from a set of HTTP-fields.
string_view_t to_string_view(extraction_error_t what) noexcept
Helper function to get a string name of extraction_error enum.
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.
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.
extraction_error_t
Error codes for failures of extraction of bearer authentification parameters.
@ no_auth_http_field
There is no HTTP field with authentification parameters.
@ not_bearer_auth_scheme
Different authentification scheme found. bearer authentification scheme is expected.
@ invalid_bearer_auth_param
Invalid value of parameter for bearer authentification scheme. The single parameter in the form of b6...
@ illegal_http_field_value
The HTTP field with authentification parameters can't be parsed.
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.
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.
expected_t< params_t, extraction_error_t > try_extract_params(const generic_request_t< Extra_Data > &req, string_view_t auth_field_name)
Helper function for getting parameters of bearer authentification from a request.
http_field_t
C++ enum that repeats nodejs c-style enum.
Tools for working with the value of Authorization HTTP-field.
authorization_details::token68_t token68_t
Type for holding a value of token68 from RFC7235.
Parameters for bearer authentification.
std::string token
Access Token.