JWT token creation and verification utilities.
More...
#include <auth.h>
|
| static std::string | createToken (const json &claims_params, int timeout=-1) |
| | Create JWT token with custom claims.
|
| |
| static json | verifyToken (const std::string &token) |
| | Verify JWT token and extract claims.
|
| |
JWT token creation and verification utilities.
Provides static methods for generating and validating JWT tokens used for authentication and authorization.
json claims = {{
"id",
"user123"}, {
"table",
"users"}};
if (result["verified"].get<bool>()) {
std::string userId = result["id"];
}
static json verifyToken(const std::string &token)
Verify JWT token and extract claims.
Definition auth.cpp:54
static std::string createToken(const json &claims_params, int timeout=-1)
Create JWT token with custom claims.
Definition auth.cpp:10
nlohmann::json json
Shorten JSON namespace.
Definition context_store.h:18
◆ createToken()
| std::string mb::Auth::createToken |
( |
const json & |
claims_params, |
|
|
int |
timeout = -1 |
|
) |
| |
|
static |
Create JWT token with custom claims.
- Parameters
-
| claims_params | JSON object with claims (must include "id" and "table") |
| timeout | Token expiration in seconds (-1 for default, typically 1 hour) |
- Returns
- JWT token string
json claims = {{
"id",
"user123"}, {
"table",
"users"}};
◆ verifyToken()
| json mb::Auth::verifyToken |
( |
const std::string & |
token | ) |
|
|
static |
Verify JWT token and extract claims.
- Parameters
-
| token | JWT token string to verify |
- Returns
- JSON object with:
- "verified": bool indicating if token is valid
- "id": user ID from token
- "entity": entity table name from token
- "error": error message if verification failed
if (result["verified"]) {
}
The documentation for this class was generated from the following files:
- /home/runner/work/mantisbase/mantisbase/include/mantisbase/core/auth.h
- /home/runner/work/mantisbase/mantisbase/src/core/auth.cpp