Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
oauth_token.h
1#ifndef SOURCEMETA_CORE_OAUTH_TOKEN_H_
2#define SOURCEMETA_CORE_OAUTH_TOKEN_H_
3
4#ifndef SOURCEMETA_CORE_OAUTH_EXPORT
5#include <sourcemeta/core/oauth_export.h>
6#endif
7
8#include <sourcemeta/core/crypto.h>
9#include <sourcemeta/core/json.h>
10#include <sourcemeta/core/oauth_authorization.h>
11
12#include <chrono> // std::chrono::seconds
13#include <functional> // std::function
14#include <optional> // std::optional
15#include <span> // std::span
16#include <string_view> // std::string_view
17
18namespace sourcemeta::core {
19
39SOURCEMETA_CORE_OAUTH_EXPORT
41 const std::string_view code, const std::string_view redirect_uri,
42 const std::string_view code_verifier,
43 const std::span<const OAuthParameter> resources, SecureString &sink)
44 -> void;
45
64SOURCEMETA_CORE_OAUTH_EXPORT
66 const std::string_view refresh_token, const std::string_view scope,
67 const std::span<const OAuthParameter> resources, SecureString &sink)
68 -> void;
69
86SOURCEMETA_CORE_OAUTH_EXPORT
88 const std::string_view scope,
89 const std::span<const OAuthParameter> resources, SecureString &sink)
90 -> void;
91
100 std::string_view grant_type;
103 std::string_view code;
106 std::string_view redirect_uri;
108 std::string_view code_verifier;
110 std::string_view refresh_token;
112 std::string_view scope;
113};
114
140SOURCEMETA_CORE_OAUTH_EXPORT
142 const std::string_view body, SecureString &storage,
143 OAuthTokenRequest &result,
144 const std::function<void(std::string_view, std::string_view)> &on_other)
145 -> bool;
146
166class SOURCEMETA_CORE_OAUTH_EXPORT OAuthTokenResponse {
167public:
169 explicit OAuthTokenResponse(const JSON &data);
170
172 [[nodiscard]] auto access_token() const -> std::optional<std::string_view>;
173
175 [[nodiscard]] auto token_type() const -> std::optional<std::string_view>;
176
179 [[nodiscard]] auto is_bearer_token_type() const -> bool;
180
183 [[nodiscard]] auto expires_in() const -> std::optional<std::chrono::seconds>;
184
186 [[nodiscard]] auto refresh_token() const -> std::optional<std::string_view>;
187
189 [[nodiscard]] auto scope() const -> std::optional<std::string_view>;
190
193 [[nodiscard]] auto has_scope(const std::string_view value) const -> bool;
194
197 [[nodiscard]] auto data() const -> const JSON &;
198
199private:
200 const JSON *data_;
201};
202
209 std::string_view access_token;
211 std::string_view token_type;
214 std::optional<std::chrono::seconds> expires_in;
216 std::string_view refresh_token;
221 std::string_view scope;
224 std::string_view requested_scope;
225};
226
243SOURCEMETA_CORE_OAUTH_EXPORT
245
259SOURCEMETA_CORE_OAUTH_EXPORT
260auto oauth_make_token_error_response(const std::string_view error,
261 const std::string_view error_description,
262 const std::string_view error_uri) -> JSON;
263
264} // namespace sourcemeta::core
265
266#endif
Definition crypto_secure.h:162
Definition json_value.h:39
std::optional< std::chrono::seconds > expires_in
Definition oauth_token.h:214
std::string_view refresh_token
The refresh token, for the refresh grant (RFC 6749 Section 6).
Definition oauth_token.h:110
OAuthTokenResponse(const JSON &data)
Construct a view over a token response document, which is borrowed.
auto data() const -> const JSON &
std::string_view redirect_uri
Definition oauth_token.h:106
std::string_view code
Definition oauth_token.h:103
std::string_view scope
The space-delimited requested scope (RFC 6749 Section 3.3).
Definition oauth_token.h:112
std::string_view requested_scope
Definition oauth_token.h:224
auto is_bearer_token_type() const -> bool
std::string_view access_token
The issued access token (RFC 6749 Section 5.1).
Definition oauth_token.h:209
std::string_view grant_type
The grant type (RFC 6749 Section 4.1.3).
Definition oauth_token.h:100
auto scope() const -> std::optional< std::string_view >
The granted scope (RFC 6749 Section 5.1), or no value when absent.
auto token_type() const -> std::optional< std::string_view >
The access token type (RFC 6749 Section 5.1), or no value when absent.
auto has_scope(const std::string_view value) const -> bool
auto access_token() const -> std::optional< std::string_view >
The issued access token (RFC 6749 Section 5.1), or no value when absent.
auto refresh_token() const -> std::optional< std::string_view >
The issued refresh token (RFC 6749 Section 5.1), or no value when absent.
auto expires_in() const -> std::optional< std::chrono::seconds >
std::string_view token_type
The token type, such as Bearer (RFC 6749 Section 7.1).
Definition oauth_token.h:211
std::string_view code_verifier
The PKCE code verifier (RFC 7636 Section 4.5).
Definition oauth_token.h:108
std::string_view refresh_token
The issued refresh token, omitted when absent (RFC 6749 Section 5.1).
Definition oauth_token.h:216
std::string_view scope
Definition oauth_token.h:221
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_token_error_response(const std::string_view error, const std::string_view error_description, const std::string_view error_uri) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_token_response(const OAuthTokenGrant &grant) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_refresh(const std::string_view refresh_token, const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_client_credentials(const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_token_request(const std::string_view body, SecureString &storage, OAuthTokenRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_code(const std::string_view code, const std::string_view redirect_uri, const std::string_view code_verifier, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
Definition oauth_token.h:207
Definition oauth_token.h:98