get_current_license
Reads the current in-session license authorization context.
get_current_license() returns the current license authorization context as the
public blaze::license result object.
Function variants
blaze::license get_current_license();
blaze::license get_current_license(std::error_code& ec) noexcept;
void async_get_current_license(std::function<void(std::error_code, blaze::license)> callback);
blaze::coro::awaitable_result<blaze::license> co_get_current_license();Status vs error
license.status is the API result. std::error_code and
std::system_error are used for transport/runtime failures only.
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.
| Field | Practical check |
|---|---|
license.key | license.key.empty() |
license.levels | license.levels.empty() |
license.comment | license.comment.empty() |
license.ip_address | license.ip_address.empty() |
license.time_left | license.time_left.count() == 0 means no expiration metadata was provided. license.time_left.count() <= 0 means there is no positive remaining time. |
Behavior notes
- Call
get_current_licenseonly after successfulconnectandinitialize. - This method reads the current in-session license context. It does not perform a new authorization request.
- It works only for license-based authorization context. If the session is not authorized by license, the operation returns
blaze::status::not_authorized. - If the server omits
levels,comment,ip_address, ortime_left, the library returns default values. - If the server does not include expiration metadata,
time_leftremains0s. - If
license.status == blaze::status::license_expired, the library can still contain useful license metadata such askey,levels, andcomment.
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 auth_result = session.authorize(license_key);
if (!auth_result.good()) {
print_status("Authorize returned status", auth_result.status);
return 1;
}
const blaze::license current_license = session.get_current_license();
if (!current_license.good() && !current_license.expired()) {
print_status("Get-current-license returned status", current_license.status);
return 1;
}
std::cout << "Current license key: " << current_license.key << '\n';
std::cout << "Levels count: " << current_license.levels.size() << '\n';
std::cout << "Time left: " << current_license.time_left.count() << "s\n";
if (current_license.expired()) {
print_status("Current-license status", current_license.status);
}
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Get-current-license failed", e.code());
return 1;
}
return 0;
}Get-current-license statuses
| Value | Status | Returned when |
|---|---|---|
1 | ok | Current license data was returned successfully. |
3 | not_authorized | Session is not currently authorized by license. |
103 | license_expired | Current license context exists, but the license is already expired. |
Connection-level shutdowns
Normal current-license results are returned in
license.status. The websocket may still be closed by session-level guards:
| Close code | Meaning | When it can happen |
|---|---|---|
4200 | not_initialized | get_current_license was called before a successful initialize. |
4201 | rate_limited | Session or IP rate limiting closed the websocket around this operation. |