mirror of
https://github.com/allankoechke/jwt-cpp.git
synced 2026-11-30 10:18:40 +00:00
adding verification test
This commit is contained in:
@@ -1582,7 +1582,12 @@ namespace jwt {
|
||||
}
|
||||
}
|
||||
else if (c.get_type() == json::type::object) {
|
||||
if( c.to_json().serialize() != jc.to_json().serialize())
|
||||
auto serialize = [](const value_type& value) {
|
||||
std::ostringstream oss;
|
||||
oss << value;
|
||||
return oss.str();
|
||||
};
|
||||
if( serialize(c.to_json()) != serialize(jc.to_json()))
|
||||
throw token_verification_exception("claim " + key + " does not match expected");
|
||||
}
|
||||
else if (c.get_type() == json::type::string) {
|
||||
|
||||
@@ -144,3 +144,14 @@ TEST(NholmannTest, SetObject) {
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
}
|
||||
|
||||
TEST(NholmannTest, VerifyTokenHS256) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify<jwt::default_clock, JWT_NHOLMANN_CLAIM_TPL>({})
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode<JWT_NHOLMANN_CLAIM_TPL>(token);
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user