userver: samples/postgres_auth/user_info_cache.hpp
Loading...
Searching...
No Matches
samples/postgres_auth/user_info_cache.hpp
#pragma once
#include <vector>
#include <userver/server/auth/user_auth_info.hpp>
namespace samples::pg {
struct UserDbInfo {
std::int64_t user_id;
std::vector<std::string> scopes;
std::string name;
};
struct AuthCachePolicy {
static constexpr std::string_view kName = "auth-pg-cache";
using ValueType = UserDbInfo;
static constexpr auto kKeyMember = &UserDbInfo::token;
static constexpr const char* kQuery =
"SELECT token, user_id, scopes, name FROM auth_schema.tokens";
static constexpr const char* kUpdatedField = "updated";
using UpdatedFieldType = storages::postgres::TimePointTz;
// Using crypto::algorithm::StringsEqualConstTimeComparator to avoid timing
// attack at find(token).
using CacheContainer =
std::unordered_map<server::auth::UserAuthInfo::Ticket, UserDbInfo,
std::hash<server::auth::UserAuthInfo::Ticket>,
};
} // namespace samples::pg