mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 01:08:31 +00:00
Fix string view overload for claim value
This commit is contained in:
parent
98ea0d6e58
commit
f8eebbede0
3 changed files with 35 additions and 1 deletions
|
@ -300,7 +300,9 @@ public: // Exposed APIs
|
||||||
*/
|
*/
|
||||||
template <typename T,
|
template <typename T,
|
||||||
typename=typename std::enable_if_t<
|
typename=typename std::enable_if_t<
|
||||||
!std::is_same<system_time_t, std::decay_t<T>>::value>
|
!std::is_same<system_time_t, std::decay_t<T>>::value ||
|
||||||
|
!std::is_same<jwt::string_view, std::decay_t<T>>::value
|
||||||
|
>
|
||||||
>
|
>
|
||||||
bool add_claim(const string_view cname, T&& cvalue, bool overwrite=false)
|
bool add_claim(const string_view cname, T&& cvalue, bool overwrite=false)
|
||||||
{
|
{
|
||||||
|
@ -320,6 +322,13 @@ public: // Exposed APIs
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
bool add_claim(const string_view cname, const string_view cvalue, bool overwrite=false)
|
||||||
|
{
|
||||||
|
return add_claim(cname, std::string{cvalue.data(), cvalue.length()}, overwrite);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
bool add_claim(const string_view cname, system_time_t tp, bool overwrite=false)
|
bool add_claim(const string_view cname, system_time_t tp, bool overwrite=false)
|
||||||
|
|
Binary file not shown.
|
@ -155,6 +155,31 @@ TEST (EncodeTest, StrEncodeHS512WithKey)
|
||||||
EXPECT_EQ (enc_str, expected_sign);
|
EXPECT_EQ (enc_str, expected_sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST (EncodeTest, StrEncodeChangeAlg)
|
||||||
|
{
|
||||||
|
using namespace jwt::params;
|
||||||
|
|
||||||
|
const char* expected_none_sign =
|
||||||
|
"eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
|
||||||
|
|
||||||
|
jwt::string_view key = "00112233445566778899";
|
||||||
|
|
||||||
|
std::map<std::string, jwt::string_view> p;
|
||||||
|
p["aud"] = "rift.io";
|
||||||
|
p["sub"] = "nothing much";
|
||||||
|
|
||||||
|
jwt::jwt_object obj{algorithm(jwt::algorithm::HS512),
|
||||||
|
secret(key),
|
||||||
|
payload(std::move(p))
|
||||||
|
};
|
||||||
|
obj.add_claim("exp", 1513863371);
|
||||||
|
|
||||||
|
obj.header().algo("none");
|
||||||
|
std::string enc_str = obj.signature();
|
||||||
|
|
||||||
|
EXPECT_EQ (expected_none_sign, enc_str);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue