C++ APISession methods

authorize(license)

Authorizes the current initialized session using a license key.

authorize(std::string license) binds the current initialized session to a license and returns the public blaze::license result object.

Function variants

blaze::license authorize(std::string license);
blaze::license authorize(std::string license, std::error_code& ec) noexcept;
void async_authorize(std::string license, std::function<void(std::error_code, blaze::license)> callback);
blaze::coro::awaitable_result<blaze::license> co_authorize(std::string license);

Status vs error

license.status is the API result. std::error_code and std::system_error are used for transport/runtime failures only.

Parameters

Prop

Type

Result

struct license {
  std::string key;
  std::vector<std::string> levels;
  std::string comment;
  std::string ip_address;
  std::chrono::seconds time_left{};
  blaze::status status{};

  bool good() const noexcept;
  bool paused() const noexcept;
  bool expired() const noexcept;
  bool blacklisted() const noexcept;
  bool already_authorized() const noexcept;
  std::string comment_or(std::string value) const;
};

Prop

Type

license.good() is equivalent to status == blaze::status::ok.

Checking returned fields

Missing fields are returned as default values. If license.status != blaze::status::ok, treat metadata fields as optional in practice and check them explicitly.

FieldPractical check
license.levelslicense.levels.empty()
license.commentlicense.comment.empty()
license.ip_addresslicense.ip_address.empty()
license.time_leftlicense.time_left.count() == 0

About license.key

license.key can also be empty when the library rejects the input locally before sending a request, for example on invalid license length. Use license.key.empty() if you need to check it explicitly.

Behavior notes

  • Call authorize only after successful connect and initialize.
  • License length is validated locally before the request is sent. On local validation failure, transport error is empty and license.status contains the returned API status.
  • If the server omits levels, comment, ip_address, or time_left, the library returns default values.
  • In current server behavior, time_left has two meanings:
    • newly activated license: unix expiration timestamp;
    • already activated license: remaining seconds.
  • If the server does not include time metadata for the current status, time_left remains 0s.

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 {
    session.connect();

    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;
    }

    std::cout << "Authorized license: " << license.key << '\n';
    std::cout << "Levels count: " << license.levels.size() << '\n';
    std::cout << "Comment: " << license.comment_or("<empty>") << '\n';
    std::cout << "IP address: " << (license.ip_address.empty() ? "<empty>" : license.ip_address) << '\n';
    std::cout << "Time left/raw time value: " << license.time_left.count() << '\n';

    session.shutdown();
  } catch (const std::system_error& e) {
    print_error_code("Authorize failed", e.code());
    return 1;
  }

  return 0;
}

Authorize statuses

ValueStatusReturned when
1okLicense authorization succeeded.
6internal_server_errorServer could not complete license authorization because of an internal error.
7already_authorizedCurrent session is already authorized.
100license_not_foundLicense does not exist in the current application.
101license_too_shortlicense is shorter than 6 characters. This is rejected locally before the request is sent.
102license_too_longlicense is longer than 64 characters. This is rejected locally before the request is sent.
103license_expiredLicense exists but is expired.
104license_pausedLicense exists but is paused.
105license_blacklistedLicense exists but is blacklisted.
502client_id_mismatchLicense is already bound to another client identifier.
602app_sessions_quota_exceededApplication authorized session quota was reached.

Connection-level shutdowns

Normal authorization results are returned in license.status. The websocket may still be closed by session-level guards:

Close codeMeaningWhen it can happen
4200not_initializedauthorize was called before a successful initialize.
4201rate_limitedSession or IP rate limiting closed the websocket around this operation.

On this page