C++ APISession methods

blacklist

Adds the current session identity context to blacklist and returns the API result.

blacklist(std::string comment = "") adds the current session identity context to blacklist and returns blaze::status.

Function variants

blaze::status blacklist(std::string comment = "");
blaze::status blacklist(std::string comment, std::error_code& ec) noexcept;
void async_blacklist(std::string comment, std::function<void(std::error_code, blaze::status)> callback);
blaze::coro::awaitable_result<blaze::status> co_blacklist(std::string comment);

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.

Parameters

Prop

Type

Result

blaze::status

Use direct comparison, for example:

if (status == blaze::status::ok) {
  // success
}

Behavior notes

  • Call blacklist only after successful connect and initialize.
  • comment is optional. If it is empty, the field is omitted from the request.
  • On blaze::status::ok, the server accepts the blacklist operation and then closes the websocket with blaze::close_code::session_blacklisted.
  • On non-success statuses, the operation returns a regular API result and the session remains usable unless another session-level guard closes it.
  • If you need to observe the server-initiated disconnect, set on_shutdown(...) before calling blacklist.

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 blacklist_comment = read_line("Blacklist comment (optional)");

  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::status blacklist_status = session.blacklist(blacklist_comment);
    if (blacklist_status != blaze::status::ok) {
      print_status("Blacklist returned status", blacklist_status);
      return 1;
    }

    std::cout << "Blacklist accepted. Server will close the session.\n";
  } catch (const std::system_error& e) {
    print_error_code("Blacklist failed", e.code());
    return 1;
  }

  return 0;
}

Blacklist statuses

ValueStatusReturned when
1okBlacklist operation was accepted successfully.
6internal_server_errorServer could not complete blacklist processing because of an internal error.
604app_blacklists_quota_exceededApplication blacklist quota was reached.

Connection-level shutdowns

Normal blacklist results are returned as blaze::status. A successful blacklist also leads to a server-initiated close:

Close codeMeaningWhen it can happen
4200not_initializedblacklist was called before a successful initialize.
4201rate_limitedSession or IP rate limiting closed the websocket around this operation.
4203session_blacklistedBlacklist succeeded and the server terminated the session.

On this page