1#ifndef SOURCEMETA_CORE_OAUTH_DEVICE_H_
2#define SOURCEMETA_CORE_OAUTH_DEVICE_H_
4#ifndef SOURCEMETA_CORE_OAUTH_EXPORT
5#include <sourcemeta/core/oauth_export.h>
8#include <sourcemeta/core/crypto.h>
9#include <sourcemeta/core/json.h>
10#include <sourcemeta/core/oauth_authorization.h>
11#include <sourcemeta/core/oauth_error.h>
21namespace sourcemeta::core {
25#pragma warning(disable : 4251)
45SOURCEMETA_CORE_OAUTH_EXPORT
47 const std::string_view client_id,
const std::string_view scope,
48 const std::span<const OAuthParameter> resources, std::string &sink) -> void;
68SOURCEMETA_CORE_OAUTH_EXPORT
70 const std::string_view device_code,
71 const std::span<const OAuthParameter> resources,
SecureString &sink)
98 [[nodiscard]]
auto device_code() const -> std::optional<std::string_view>;
100 [[nodiscard]] auto
user_code() const -> std::optional<std::string_view>;
103 -> std::optional<std::string_view>;
106 -> std::optional<std::string_view>;
109 [[nodiscard]] auto
expires_in() const -> std::optional<std::chrono::seconds>;
112 [[nodiscard]] auto
interval() const -> std::chrono::seconds;
164 const std::chrono::seconds lifetime,
165 const std::chrono::steady_clock::time_point start)
noexcept;
168 [[nodiscard]]
auto interval() const noexcept -> std::chrono::seconds;
172 expired(const std::chrono::steady_clock::time_point now) const noexcept
183 std::chrono::seconds interval_;
184 std::chrono::seconds lifetime_;
185 std::chrono::steady_clock::time_point start_;
212SOURCEMETA_CORE_OAUTH_EXPORT
214 const std::string_view device_code,
const std::string_view user_code,
215 const std::string_view verification_uri,
216 const std::string_view verification_uri_complete,
217 const std::chrono::seconds expires_in,
const std::chrono::seconds interval)
218 -> std::optional<JSON>;
233SOURCEMETA_CORE_OAUTH_EXPORT
249SOURCEMETA_CORE_OAUTH_EXPORT
251 const std::string_view stored) -> bool;
auto verification_uri() const -> std::optional< std::string_view >
The end-user verification URI (RFC 8628 Section 3.2).
auto device_code() const -> std::optional< std::string_view >
The device verification code (RFC 8628 Section 3.2).
auto observe(const OAuthTokenError error) noexcept -> OAuthDevicePollDecision
auto interval() const -> std::chrono::seconds
OAuthDevicePoller(const std::chrono::seconds interval, const std::chrono::seconds lifetime, const std::chrono::steady_clock::time_point start) noexcept
auto interval() const noexcept -> std::chrono::seconds
The current polling interval, which a slow_down error grows.
auto data() const -> const JSON &
The underlying document.
auto user_code() const -> std::optional< std::string_view >
The end-user verification code (RFC 8628 Section 3.2).
OAuthDeviceAuthorizationResponse(const JSON &data)
Construct a view over a device authorization response, which is borrowed.
auto verification_uri_complete() const -> std::optional< std::string_view >
The verification URI with the user code included (RFC 8628 Section 3.2).
auto expired(const std::chrono::steady_clock::time_point now) const noexcept -> bool
Whether the codes have expired locally by the given time.
auto expires_in() const -> std::optional< std::chrono::seconds >
OAuthDevicePollDecision
Definition oauth_device.h:124
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_device_user_code() -> std::array< char, 8 >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_device_user_code_matches(const std::string_view presented, const std::string_view stored) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_device_authorization_response(const std::string_view device_code, const std::string_view user_code, const std::string_view verification_uri, const std::string_view verification_uri_complete, const std::chrono::seconds expires_in, const std::chrono::seconds interval) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_device_authorization_request(const std::string_view client_id, const std::string_view scope, const std::span< const OAuthParameter > resources, std::string &sink) -> void
OAuthTokenError
Definition oauth_error.h:42
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_device(const std::string_view device_code, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
@ Denied
The end user denied the request.
Definition oauth_device.h:132
@ Error
Definition oauth_device.h:137
@ Continue
Keep polling at the current interval.
Definition oauth_device.h:126
@ RetryWithNonce
Definition oauth_device.h:130
@ Expired
The assertion has expired (RFC 7523 Section 3 check 4).
Definition oauth_assertion.h:147