Skip to content

Commit

Permalink
adding verification test
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc committed May 21, 2020
1 parent 8ba9dc1 commit 474a870
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/jwt-cpp/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/NlohmannTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 474a870

Please sign in to comment.