MySQL 9.1.0
Source Code Documentation
http_auth.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_HTTP_AUTH_INCLUDED
27#define MYSQLROUTER_HTTP_AUTH_INCLUDED
28
29#include <string>
30#include <system_error>
31#include <vector>
32
34
35#include "http_auth_realm.h"
36
37/**
38 * Quoted String.
39 *
40 * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
41 */
43 public:
44 static std::string quote(const std::string &str);
45};
46
47/**
48 * Authentication Challenge.
49 *
50 * sent by server to client when it asks client to authenticate.
51 *
52 * payload of the WWW-Authenticate header.
53 *
54 * @see https://tools.ietf.org/html/rfc7235#section-4.1
55 */
57 public:
58 /**
59 * construct challenge message.
60 */
62 const std::string &scheme, const std::string &token,
63 const std::vector<std::pair<std::string, std::string>> params)
64 : scheme_{scheme}, token_{token}, params_{params} {}
65
66 /**
67 * convert challenge message to payload of WWW-Authenticate.
68 *
69 * @returns `{scheme} {token} {params}`
70 */
71 std::string str() const;
72
73 /**
74 * authentication scheme.
75 *
76 * e.g.: Basic
77 */
78 std::string scheme() const { return scheme_; }
79
80 /**
81 * token of the challenge message.
82 *
83 * @note valid according to RFC 7235, but usually unused.
84 */
85 std::string token() const { return token_; }
86
87 /**
88 * parameters of the challenge message.
89 *
90 * e.g.: realm="secret"
91 */
92 std::vector<std::pair<std::string, std::string>> params() { return params_; }
93
94 private:
95 std::string scheme_;
96 std::string token_;
97 std::vector<std::pair<std::string, std::string>> params_;
98};
99
100/**
101 * Authorization message.
102 *
103 * sent from client to server.
104 *
105 * @see https://tools.ietf.org/html/rfc7235#section-4.2
106 */
108 public:
109 /**
110 * construct Authorization message from fields.
111 */
113 const std::string &scheme, const std::string &token,
114 const std::vector<std::pair<std::string, std::string>> params)
115 : scheme_{scheme}, token_{token}, params_{params} {}
116
117 /**
118 * parse a 'credentials' field.
119 *
120 * ec MUST be checked before using the return-value.
121 *
122 * @param hdr content of Authorization header
123 * @param ec error code
124 * @returns a HttpAuthCredentials message ... and error_code
125 */
126 static HttpAuthCredentials from_header(const std::string &hdr,
127 std::error_code &ec);
128
129 /**
130 * string representation of 'credentials'.
131 *
132 * according to RFC 7235
133 */
134 std::string str() const;
135
136 /**
137 * authentication scheme of the Authorization message.
138 *
139 * e.g.: Basic
140 */
141 std::string scheme() const { return scheme_; }
142
143 /**
144 * token part of the Authorization message.
145 *
146 * for Basic this is a Base64 encoded strings.
147 */
148 std::string token() const { return token_; }
149
150 /**
151 * params part of the Authorization message.
152 *
153 * for Bearer this is a list of params
154 */
155 std::vector<std::pair<std::string, std::string>> params() { return params_; }
156
157 private:
158 std::string scheme_;
159 std::string token_;
160 std::vector<std::pair<std::string, std::string>> params_;
161};
162
163#endif
Authentication Challenge.
Definition: http_auth.h:56
std::vector< std::pair< std::string, std::string > > params()
parameters of the challenge message.
Definition: http_auth.h:92
HttpAuthChallenge(const std::string &scheme, const std::string &token, const std::vector< std::pair< std::string, std::string > > params)
construct challenge message.
Definition: http_auth.h:61
std::string scheme_
Definition: http_auth.h:95
std::vector< std::pair< std::string, std::string > > params_
Definition: http_auth.h:97
std::string token_
Definition: http_auth.h:96
std::string token() const
token of the challenge message.
Definition: http_auth.h:85
std::string scheme() const
authentication scheme.
Definition: http_auth.h:78
Authorization message.
Definition: http_auth.h:107
std::string token_
Definition: http_auth.h:159
HttpAuthCredentials(const std::string &scheme, const std::string &token, const std::vector< std::pair< std::string, std::string > > params)
construct Authorization message from fields.
Definition: http_auth.h:112
std::string scheme() const
authentication scheme of the Authorization message.
Definition: http_auth.h:141
std::string token() const
token part of the Authorization message.
Definition: http_auth.h:148
std::string scheme_
Definition: http_auth.h:158
std::vector< std::pair< std::string, std::string > > params()
params part of the Authorization message.
Definition: http_auth.h:155
std::vector< std::pair< std::string, std::string > > params_
Definition: http_auth.h:160
Quoted String.
Definition: http_auth.h:42
#define HTTP_SERVER_LIB_EXPORT
Definition: http_server_lib_export.h:15
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2876