Public Member Functions | List of all members
xxhr::Authentication Class Reference

Some Web APIs requires authenticating via HTTP Basic auth ( i.e. base64 encoded user and password authentication). More...

Public Member Functions

template<typename UserType , typename PassType >
 Authentication (UserType &&username, PassType &&password)
 Specify username and password for basic auth.
 

Detailed Description

Passing an xxhr::Authentication is enough to transmit user and password information. In HTTP there are two ways : Basic and Digest authentication.

It is recommended to use authentication, even the Digest one only on a TLS connection.

Basic Authentication

In this example we query the Github REST search api, if you've setup 2-Factor Authentication on your github account you should use a github personal access token to test this example and use it in place of password.

Otherwise you'll get an xxhr::Response::status_code 404.

// For example connecting to the Github API v3 with your Github Credentials
GET("https://api.github.com/search/code"s,
Authentication{"username", "password"},
// Will be transmitted in cleartext base64 encoded, therefore the use of https is recommended.
Parameters{{"q", "authenticated search string"}},
on_response = [](auto&& resp) {
std::cout << resp.text;
});

Digest Authentication

To initiate a Digest authentication use in-place of xxhr::Authentication the xxhr::Digest parameter:

// For example connecting to the Github API v3 with your Github Credentials
GET("https://api.github.com/search/code"s,
Digest{"username", "password"},
// Will be transmitted as MD5 hash.
Parameters{{"q", "authenticated search string"}},
on_response = [](auto&& resp) {
std::cout << resp.text;
});

Bearer Authentication

To initiate a Bearer authentication use xxhr::Bearer parameter:

GET("http://httpbin.org/bearer"s,
Bearer{"I dont have a token but I can put it on my karma"},
on_response = [](auto&& resp) {
std::cout << resp.text;
});

The documentation for this class was generated from the following file:
xxhr::on_response
constexpr make_handler_t< on_response_ > on_response
Continuation callback ( i.e. signature : void callback(xxhr::Response)) for the asynchronous HTTP ope...
Definition: handler.hpp:39
xxhr::Authentication::Authentication
Authentication(UserType &&username, PassType &&password)
Specify username and password for basic auth.
Definition: auth.hpp:21
xxhr::GET
void GET(Ts &&... ts)
HTTP GET Request.
Definition: api.hpp:41