algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::network::AuthBody< BrokerType > Struct Template Reference

An OAuth access token and its expiry, the base of each broker's token-response class. More...

#include <algotradelib/src/network/oauth.hpp>

Inheritance diagram for algotradelib::network::AuthBody< BrokerType >:

Public Member Functions

void from_json (const json::object &document)
 Reads a token response.
bool valid (std::chrono::seconds margin=std::chrono::minutes(5)) const noexcept
 Tests whether the token is set and stays valid for at least a margin.

Public Attributes

std::string access_token_
 The bearer token; do not log it.
std::chrono::system_clock::time_point expires_at_ {}
 When the token expires.

Detailed Description

template<typename BrokerType>
struct algotradelib::network::AuthBody< BrokerType >

An OAuth access token and its expiry, the base of each broker's token-response class.

The broker class derives from it (CRTP) and provides the static token_field() naming the token's JSON field, and from_json_impl(document) to read anything else (such as an absolute expiry).

Template Parameters
BrokerTypeThe derived broker token class.

Definition at line 131 of file oauth.hpp.

Member Function Documentation

◆ from_json()

template<typename BrokerType>
void algotradelib::network::AuthBody< BrokerType >::from_json ( const json::object & document)
inline

Reads a token response.

Reads the token, a relative expires_in (a whole number, or a string of one) if present, then calls the broker's from_json_impl, which may set an absolute expiry.

Parameters
documentThe response.
Exceptions
std::runtime_errorif the token field is missing or not a string, or the response states no expiry (no lifetime is assumed); or whatever the broker's from_json_impl throws.

Definition at line 147 of file oauth.hpp.

◆ valid()

template<typename BrokerType>
bool algotradelib::network::AuthBody< BrokerType >::valid ( std::chrono::seconds margin = std::chrono::minutes(5)) const
inlinenoexcept

Tests whether the token is set and stays valid for at least a margin.

Parameters
marginHow long it must still be valid.
Returns
true if the token is nonempty and expires later than now plus margin.

Definition at line 182 of file oauth.hpp.

Referenced by algotradelib::kis::KisRest::valid().

Member Data Documentation

◆ access_token_

template<typename BrokerType>
std::string algotradelib::network::AuthBody< BrokerType >::access_token_

The bearer token; do not log it.

Definition at line 133 of file oauth.hpp.

Referenced by from_json(), and valid().

◆ expires_at_

template<typename BrokerType>
std::chrono::system_clock::time_point algotradelib::network::AuthBody< BrokerType >::expires_at_ {}

When the token expires.

Definition at line 135 of file oauth.hpp.

Referenced by from_json(), and valid().


The documentation for this struct was generated from the following file: