C++ SDK

The C++ account client is in cpp/auth.hpp in mesgd-sdk. Use it to enroll an account, obtain a session, and manage public keys independently of the PKI layer. The examples use an existing account named alice; passwords and authenticator codes come from the application rather than literals in source.

Support status

CapabilityCurrent support
Account operationsAvailable: signup, confirmation, login, reset, keys, key updates, and logout
HTTPSAvailable through the C libcurl bridge; C++ has offline contract coverage
WSSPending supported SDK message client; experimental samples are not current-server integration

Completeness position: 13 of 18. Account contract tests and the C HTTPS bridge; PKI still uses the older implementation and missing WSS headers. The language matrix explains the ranking criteria and comparable tiers. WSS readiness is listed separately; no SDK currently provides a complete, validated encrypted messaging workflow against this server.

Setup and transport

Include cpp/auth.hpp and link the C auth implementation and cJSON. For HTTPS, also compile c/auth_curl.c and link libcurl. Compile the C files as C and link their objects into the C++ application; the wrapper requires C++17.

mesgd::AuthClient accepts a std::function transport. The lambda below forwards to the provided C libcurl implementation. Initialize libcurl globally before invoking the function, and keep its configuration alive for as long as the client uses it.

A custom transport must serialize JSON, attach Authorization: Bearer TOKEN only when a token is supplied, verify the certificate and hostname, reject redirects, and use a finite timeout. Its origin is an HTTPS URL, such as https://mesgd.example.com, rather than a WebSocket URL.

Log in, read keys, and log out

Pass the current authenticator code as a six-digit string, preserving leading zeroes. This example reads the account's published keys and ends the session on its successful path. Applications that retain a session can keep the bearer until logout or expiry instead.

#include "auth.hpp"
#include <string>
#include "../c/auth_curl.h"

mesgd::Json read_keys(const char *password, const char *otp) {
    mesgd_auth_curl_config config{"https://mesgd.example.com", nullptr};
    mesgd::AuthClient client([&](const char *method, const char *path,
                                const cJSON *body, const char *token, cJSON **out) {
        return mesgd_auth_curl_transport(&config, method, path, body, token, out);
    });
    auto session = client.login("alice", password, otp);
    const auto *item = cJSON_GetObjectItemCaseSensitive(session.get(), "access_token");
    if (!cJSON_IsString(item)) throw std::runtime_error("invalid session response");
    std::string token(item->valuestring);
    auto keys = client.keys(token.c_str());
    client.logout(token.c_str());
    return keys;
}

Responses are mesgd::Json, a unique_ptr that calls cJSON_Delete. Read JSON through .get() and copy strings that must outlive the response. HTTP failures throw mesgd::AuthError with status. The separate C++ PKI implementation is still being rewritten; the auth wrapper does not establish parity with the shared PKI tests.

Enroll a new account

The following fragment uses an existing client or transport from the example above. Signup returns a pending enrollment. Display qr_png_base64 or otpauth_uri, let the person configure the authenticator, then collect a code to confirm it. These calls are separate application steps, with user interaction between them.

auto enrollment = client.signup("alice", "alice@example.com", password);
// Display enrollment and copy its enrollment_token into a std::string.
auto session = client.confirm("alice", enrollment_token.c_str(), enrollment_otp);
// Copy the recovery_codes for the application's one-time display.

Confirmation returns the first session and eight recovery codes. Display the recovery codes for separate safekeeping. A code accepted for confirmation cannot be reused for login or a key update; wait for a new authenticator step before another operation that consumes a code.

Account operations

OperationFunction or methodHTTP endpoint
Create a pending accountsignupPOST /auth/signup
Confirm authenticator enrollmentconfirmPOST /auth/signup/confirm
Log inloginPOST /auth/login
Reset a forgotten passwordreset_passwordPOST /auth/password/reset
Read account public keyskeysGET /auth/keys
Replace account public keysset_keysPUT /auth/keys
End the current sessionlogoutPOST /auth/logout

A key update takes the session token, current password, a fresh authenticator code, and an array containing only public JWKs. An empty array clears the linked keys. A password reset takes the username, a saved recovery code, a new password, and a fresh authenticator code; success replaces the recovery codes and revokes existing sessions without returning a new session.

The shared authentication reference documents argument order, response fields, and transport behavior. Session refresh is available through the HTTP API but is not wrapped by these seven SDK operations.

Message connections

The C++ ping/pong sample includes root-level pki.hh and mesgd.hh, which are absent from this checkout. Its use of Boost.Beast does not provide the missing SDK wrapper.

Account login does not establish a message connection. The current server accepts JSON WebSocket frames and can authenticate an upgrade with a login session or an issued grant token. Login sessions carry identity without path restrictions; grants limit routing to assigned patterns. See WebSocket and Routing.

The encrypted registration handshake in the ping/pong samples is not implemented by the current mesgd listener. Treat those samples as experimental cryptographic examples, with compatibility limits described in Samples.

Validation

From the mesgd-sdk repository root, run the account contract suite for this language:

python3 tests/test_auth.py --language cpp

This is an offline request-contract check. Missing toolchains are reported as skips. See Languages for live HTTPS and PKI test coverage.