mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-16 17:58:32 +00:00
Readme changes for example code and fixed header decoding
This commit is contained in:
parent
1236071a4f
commit
6302055db1
22 changed files with 1077 additions and 6 deletions
21
examples/simple_ex1.cc
Normal file
21
examples/simple_ex1.cc
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <iostream>
|
||||
#include "jwt/jwt.hpp"
|
||||
|
||||
int main() {
|
||||
using namespace jwt::params;
|
||||
|
||||
auto key = "secret"; //Secret to use for the algorithm
|
||||
//Create JWT object
|
||||
jwt::jwt_object obj{algorithm("HS256"), payload({{"some", "payload"}}), secret(key)};
|
||||
|
||||
//Get the encoded string/assertion
|
||||
auto enc_str = obj.signature();
|
||||
std::cout << enc_str << std::endl;
|
||||
|
||||
//Decode
|
||||
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret(key));
|
||||
std::cout << dec_obj.header() << std::endl;
|
||||
std::cout << dec_obj.payload() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue