ORE Studio 0.0.4
Loading...
Searching...
No Matches
jwt_claims.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_SECURITY_JWT_JWT_CLAIMS_HPP
21#define ORES_SECURITY_JWT_JWT_CLAIMS_HPP
22
23#include <string>
24#include <vector>
25#include <chrono>
26#include <optional>
27
28namespace ores::security::jwt {
29
33struct jwt_claims final {
37 std::string subject;
38
42 std::string issuer;
43
47 std::string audience;
48
52 std::chrono::system_clock::time_point expires_at;
53
57 std::chrono::system_clock::time_point issued_at;
58
62 std::vector<std::string> roles;
63
67 std::optional<std::string> username;
68
72 std::optional<std::string> email;
73
81 std::optional<std::string> session_id;
82
90 std::optional<std::chrono::system_clock::time_point> session_start_time;
91
97 std::optional<std::string> tenant_id;
98
104 std::optional<std::string> party_id;
105
112 std::vector<std::string> visible_party_ids;
113
123 static jwt_claims with_ttl(std::chrono::seconds ttl) {
124 jwt_claims c;
125 c.issued_at = std::chrono::system_clock::now();
126 c.expires_at = c.issued_at + ttl;
127 return c;
128 }
129};
130
131}
132
133#endif
Represents the claims extracted from a JWT token.
Definition jwt_claims.hpp:33
std::string subject
Subject claim - typically the account ID.
Definition jwt_claims.hpp:37
std::optional< std::string > session_id
Optional session ID for tracking sessions.
Definition jwt_claims.hpp:81
std::chrono::system_clock::time_point issued_at
Time when the token was issued.
Definition jwt_claims.hpp:57
std::optional< std::string > tenant_id
Optional tenant ID (UUID string).
Definition jwt_claims.hpp:97
std::optional< std::string > party_id
Optional party ID (UUID string, nil UUID if no party selected).
Definition jwt_claims.hpp:104
std::optional< std::chrono::system_clock::time_point > session_start_time
Optional session start time for efficient database updates.
Definition jwt_claims.hpp:90
static jwt_claims with_ttl(std::chrono::seconds ttl)
Create a claims object with issued_at set to now and expires_at set to now + ttl.
Definition jwt_claims.hpp:123
std::string audience
Intended audience for the token.
Definition jwt_claims.hpp:47
std::vector< std::string > visible_party_ids
List of visible party IDs (UUID strings) for the session.
Definition jwt_claims.hpp:112
std::optional< std::string > username
Optional username claim.
Definition jwt_claims.hpp:67
std::chrono::system_clock::time_point expires_at
Time when the token expires.
Definition jwt_claims.hpp:52
std::vector< std::string > roles
User roles/permissions.
Definition jwt_claims.hpp:62
std::string issuer
Issuer of the token.
Definition jwt_claims.hpp:42
std::optional< std::string > email
Optional email claim.
Definition jwt_claims.hpp:72