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 {
24#pragma warning(disable : 4251)
44SOURCEMETA_CORE_OAUTH_EXPORT
46 const std::string_view client_id,
const std::string_view scope,
47 const std::span<const OAuthParameter> resources, std::string &sink) -> void;
67SOURCEMETA_CORE_OAUTH_EXPORT
69 const std::string_view device_code,
70 const std::span<const OAuthParameter> resources,
SecureString &sink)
97 [[nodiscard]]
auto device_code() const -> std::optional<std::string_view>;
99 [[nodiscard]] auto
user_code() const -> std::optional<std::string_view>;
102 -> std::optional<std::string_view>;
105 -> std::optional<std::string_view>;
108 [[nodiscard]] auto
expires_in() const -> std::optional<std::chrono::seconds>;
111 [[nodiscard]] auto
interval() const -> std::chrono::seconds;
163 const std::chrono::seconds lifetime,
164 const std::chrono::steady_clock::time_point start)
noexcept;
167 [[nodiscard]]
auto interval() const noexcept -> std::chrono::seconds;
171 expired(const std::chrono::steady_clock::time_point now) const noexcept
182 std::chrono::seconds interval_;
183 std::chrono::seconds lifetime_;
184 std::chrono::steady_clock::time_point start_;
188#pragma warning(default : 4251)
211SOURCEMETA_CORE_OAUTH_EXPORT
213 const std::string_view device_code,
const std::string_view user_code,
214 const std::string_view verification_uri,
215 const std::string_view verification_uri_complete,
216 const std::chrono::seconds expires_in,
const std::chrono::seconds interval)
217 -> std::optional<JSON>;
232SOURCEMETA_CORE_OAUTH_EXPORT
248SOURCEMETA_CORE_OAUTH_EXPORT
250 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:123
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:131
@ Error
Definition oauth_device.h:136
@ Continue
Keep polling at the current interval.
Definition oauth_device.h:125
@ RetryWithNonce
Definition oauth_device.h:129
@ Expired
The assertion has expired (RFC 7523 Section 3 check 4).
Definition oauth_assertion.h:147