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