29 lines
792 B
C++
29 lines
792 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <chrono>
|
|
|
|
namespace scar {
|
|
|
|
class JWT {
|
|
public:
|
|
// Generate JWT token for username with expiration
|
|
static std::string generate(const std::string& username,
|
|
const std::string& secret,
|
|
std::chrono::seconds expiration = std::chrono::hours(24));
|
|
|
|
// Verify and decode JWT token
|
|
static bool verify(const std::string& token, const std::string& secret);
|
|
|
|
// Extract username from token (without verification)
|
|
static std::string extractUsername(const std::string& token);
|
|
|
|
// Check if token is expired
|
|
static bool isExpired(const std::string& token);
|
|
|
|
private:
|
|
static constexpr const char* ISSUER = "scarchat-server";
|
|
};
|
|
|
|
} // namespace scar
|