mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Added new parameters for decode API
This commit is contained in:
parent
de38b3a82a
commit
09bc72c9f7
6 changed files with 107 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <set>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <ostream>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
@ -17,6 +18,7 @@
|
|||
|
||||
// For convenience
|
||||
using json_t = nlohmann::json;
|
||||
using system_time_t = std::chrono::time_point<std::chrono::system_clock>;
|
||||
|
||||
namespace jwt {
|
||||
|
||||
|
@ -296,7 +298,10 @@ public: // 'tors
|
|||
public: // Exposed APIs
|
||||
/**
|
||||
*/
|
||||
template <typename T>
|
||||
template <typename T,
|
||||
typename=typename std::enable_if_t<
|
||||
!std::is_same<system_time_t, std::decay_t<T>>::value>
|
||||
>
|
||||
bool add_claim(const string_view cname, T&& cvalue, bool overwrite=false)
|
||||
{
|
||||
// Duplicate claim names not allowed
|
||||
|
@ -315,6 +320,17 @@ public: // Exposed APIs
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
bool add_claim(const string_view cname, system_time_t tp, bool overwrite=false)
|
||||
{
|
||||
return add_claim(
|
||||
cname,
|
||||
std::chrono::duration_cast<
|
||||
std::chrono::seconds>(tp.time_since_epoch()).count()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
bool remove_claim(const string_view cname)
|
||||
|
@ -548,9 +564,15 @@ public: // Exposed APIs
|
|||
|
||||
/**
|
||||
*/
|
||||
template <typename T>
|
||||
template <typename T, typename Cond>
|
||||
jwt_object& add_claim(const string_view name, T&& value);
|
||||
|
||||
/**
|
||||
* Specialization for time points.
|
||||
* Eg: Users can set `exp` claim to `chrono::system_clock::now()`.
|
||||
*/
|
||||
jwt_object& add_claim(const string_view name, system_time_t time_point);
|
||||
|
||||
/**
|
||||
*/
|
||||
jwt_object& remove_claim(const string_view name);
|
||||
|
@ -601,10 +623,15 @@ private: // Data Members
|
|||
std::string secret_;
|
||||
};
|
||||
|
||||
/*!
|
||||
/**
|
||||
*/
|
||||
jwt_object jwt_decode(const string_view encoded_str, const string_view key, bool validate=true);
|
||||
|
||||
/**
|
||||
*/
|
||||
template <typename... Args>
|
||||
jwt_object decode(const string_view enc_str, const string_view key, Args&&... args);
|
||||
|
||||
|
||||
} // END namespace jwt
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue