MantisBase v0.4.9
Loading...
Searching...
No Matches
api_keys.h File Reference

Programmatic and REST-backed API key management. More...

#include <string>
#include <optional>
#include <nlohmann/json.hpp>
#include "types.h"
Include dependency graph for api_keys.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mb::ApiKeyResult
class  mb::MbApiKeyMgr
 Create, list, revoke, and resolve API keys for entity users and admins. More...

Namespaces

namespace  mb

Typedefs

using mb::json = nlohmann::json
 Shorten JSON namespace.

Detailed Description

Programmatic and REST-backed API key management.

API keys are long-lived credentials prefixed with mb_sk_. They authenticate via Authorization: Bearer mb_sk_... and are validated by the getAuthToken() middleware. Keys are stored hashed; the raw secret is returned only once at creation.

Access from C++ through MbAuth::apiKey() on your owned MantisBase instance.

auto app = MantisBase::create();
auto& keys = app->auth().apiKey();
auto created = keys.create("users", user_id, "CI token");
// created["key"] is shown once — store it securely
auto listed = keys.list("users", user_id); // metadata only, no raw keys
keys.revoke(created["id"].get<std::string>(), "users", user_id);