C++ APISession methods
logout
Clears the current authorization context while keeping the session connected.
logout() clears the current session authorization context and returns
blaze::status.
Function variants
blaze::status logout();
blaze::status logout(std::error_code& ec) noexcept;
void async_logout(std::function<void(std::error_code, blaze::status)> callback);
blaze::coro::awaitable_result<blaze::status> co_logout();Status vs error
The returned blaze::status is the API result. std::error_code and
std::system_error are used for transport/runtime failures only.
Result
blaze::statusUse direct comparison, for example:
if (status == blaze::status::ok) {
// success
}Behavior notes
- Call
logoutonly after successfulconnectandinitialize. logoutworks only when the session currently has an authorization context.logoutcan clear a session authorized either by license or by account credentials.- If the session is not currently authorized, the operation returns
blaze::status::not_authorized. - A successful
logoutkeeps the websocket connected and the session initialized. - After successful
logout, protected operations require a newauthorize(...)call.
Example
Compilation note
Synchronous and Asynchronous examples compile in the same form from C++17
to C++26.
#include "blazeauth/api/api.hpp"
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
void print_status(const std::string& context, blaze::status status) {
std::cout << context << ": "
<< static_cast<unsigned int>(status)
<< " (" << blaze::to_string(status) << ")\n";
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
const std::string license_key = read_line("License");
blaze::session session;
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
const blaze::application app = session.initialize(websocket_api_key, client_id);
if (!app.good()) {
print_status("Initialize returned status", app.status);
return 1;
}
const blaze::license license = session.authorize(license_key);
if (!license.good()) {
print_status("Authorize returned status", license.status);
return 1;
}
const blaze::status logout_status = session.logout();
if (logout_status != blaze::status::ok) {
print_status("Logout returned status", logout_status);
return 1;
}
std::cout << "Logged out successfully\n";
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Logout failed", e.code());
return 1;
}
return 0;
}Logout statuses
| Value | Status | Returned when |
|---|---|---|
1 | ok | Logout completed successfully. |
3 | not_authorized | Session is not currently authorized. |
Connection-level shutdowns
Normal logout results are returned as
blaze::status. The websocket may still be closed by session-level guards:
| Close code | Meaning | When it can happen |
|---|---|---|
4200 | not_initialized | logout was called before a successful initialize. |
4201 | rate_limited | Session or IP rate limiting closed the websocket around this operation. |