Skip to content

An exception free header only library for creating and validating json web tokens in c++

License

Notifications You must be signed in to change notification settings

CrHasher/jwt-cpp-noexcept

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwt-cpp-noexcept

An exception free header only library for creating and validating json web tokens in c++.

Signature algorithms

As of version 0.2.0 jwt-cpp supports all algorithms defined by the spec. The modular design of jwt-cpp allows one to add additional algorithms without any problems. If you need any feel free to open a pull request. For the sake of completeness, here is a list of all supported algorithms:

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512
  • ES256
  • ES384
  • ES512
  • PS256
  • PS384
  • PS512

Examples

Simple example of decoding a token:

#include <jwt-cpp/jwt.h>
#include <iostream>

int main(int argc, const char** argv) {
	//...
	std::string nsaID;
	jwt::decoded_jwt decodedNsaIDToken = jwt::decode(nsaIDToken, false);
	if (decodedNsaIDToken.error() == jwt::JwtErrc::NoError)
	{
		if (decodedNsaIDToken.has_payload_claim("sub"))
		{
			jwt::result_t<const jwt::claim&> sub = decodedNsaIDToken.get_payload_claim("sub");
			if (sub.second == jwt::JwtErrc::NoError)
			{
				jwt::result_t<std::string> subStr = sub.first.as_string();
				if (subStr.second == jwt::JwtErrc::NoError)
				{
					nsaID = subStr.first;
				}
			}
		}
	}
	//...
}

Dependencies

In order to use jwt-cpp you need the following tools.

  • libcrypto (openssl or compatible)
  • a compiler supporting at least c++11
  • basic stl support

About

An exception free header only library for creating and validating json web tokens in c++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%