Skip to content

Commit

Permalink
Added more algorithm
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
Stefan Kürzeder committed Jul 25, 2019
1 parent 63f64d8 commit 70f762b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,25 @@
* libssl-dev (for the header files)

## API
## Globals
### Algorithm
* `JWT_ALGORITHM_HS256`
* `JWT_ALGORITHM_HS384`
* `JWT_ALGORITHM_HS512`
* `JWT_ALGORITHM_RS256`
* `JWT_ALGORITHM_RS384`
* `JWT_ALGORITHM_RS512`

## Functions
### Function: `jwtSign`
```cpp
bool jwtSign(function(string/boolean) callback, table claims, string algorithm, string secret/public_key_path, string private_key_path)
bool jwtSign(function(string/boolean) callback, table claims, JWT_ALGORITHM algorithm, string secret/private_key_path, bool is_file_path = false)
```
* __callback:__ Lorem ipsum
* __claims:__ Lorem ipsum
* __algorithm:__ Lorem ipsum
* __secret/public_key_path__ Lorem ipsum
* __private_key_path__ Lorem ipsum
* __secret/private_key_path__ Lorem ipsum
* __is_file_path__ Lorem ipsum
Returns __true__ if everything went fine, __false__ otherwise.
Expand Down
18 changes: 17 additions & 1 deletion module/CFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm)
{
case JWT_ALGORITHM_HS256:
return jwt.sign(jwt::algorithm::hs256{ private_key });
case JWT_ALGORITHM_HS384:
return jwt.sign(jwt::algorithm::hs384{ private_key });
case JWT_ALGORITHM_HS512:
return jwt.sign(jwt::algorithm::hs512{ private_key });
case JWT_ALGORITHM_RS256:
return jwt.sign(jwt::algorithm::rs256{ "", private_key });
case JWT_ALGORITHM_RS384:
return jwt.sign(jwt::algorithm::rs384{ "", private_key });
case JWT_ALGORITHM_RS512:
return jwt.sign(jwt::algorithm::rs512{ "", private_key });
default:
break;
}
Expand Down Expand Up @@ -158,8 +166,16 @@ int CFunctions::verify_jwt_token(lua_State* lua_vm)
// set verifier algorithm
if (std::strcmp(algorithm, "HS256") == 0)
verifier.allow_algorithm(jwt::algorithm::hs256{ public_key });
else if (std::strcmp(algorithm, "RS256") == 0)
if (std::strcmp(algorithm, "HS384") == 0)
verifier.allow_algorithm(jwt::algorithm::hs384{ public_key });
if (std::strcmp(algorithm, "HS512") == 0)
verifier.allow_algorithm(jwt::algorithm::hs512{ public_key });
if (std::strcmp(algorithm, "RS256") == 0)
verifier.allow_algorithm(jwt::algorithm::rs256{ public_key });
if (std::strcmp(algorithm, "RS384") == 0)
verifier.allow_algorithm(jwt::algorithm::rs384{ public_key });
if (std::strcmp(algorithm, "RS512") == 0)
verifier.allow_algorithm(jwt::algorithm::rs512{ public_key });

verifier.verify(decoded_jwt);

Expand Down

0 comments on commit 70f762b

Please sign in to comment.