Fix cmake
This commit is contained in:
parent
46d77ee849
commit
b1ce0ec0e8
|
@ -348,16 +348,14 @@ else(JPEG_FOUND)
|
||||||
endif(JPEG_FOUND)
|
endif(JPEG_FOUND)
|
||||||
|
|
||||||
# LIBJWT
|
# LIBJWT
|
||||||
find_package(jwt)
|
find_package(LibJWT)
|
||||||
if(JWT_FOUND)
|
if(LIBJWT_FOUND)
|
||||||
set(HAVE_LIBJWT 1)
|
set(HAVE_LIBJWT 1)
|
||||||
list(APPEND ZM_LIB_BINS "${JWT_LIBRARIES}")
|
set(optlibsfound "${optlibsfound} LIBJWT")
|
||||||
include_directories("${JWT_INCLUDE_DIR}")
|
list(APPEND ZM_BIN_LIBS "${LIBJWT_LIBRARY}")
|
||||||
set(CMKAE_REQUIRED_INCLUDES "${JWT_INCLUDE_DIR}")
|
else(LIBJWT_FOUND)
|
||||||
set(optlibsfound "{optlibsfound} JWT")
|
set(optlibsnotfound "${optlibsnotfound} LIBJWT")
|
||||||
else(JWT_FOUND)
|
endif(LIBJWT_FOUND)
|
||||||
set(optlibsnotfound "${optlibsnotfound} JWT")
|
|
||||||
endif(JWT_FOUND)
|
|
||||||
|
|
||||||
# OpenSSL
|
# OpenSSL
|
||||||
find_package(OpenSSL)
|
find_package(OpenSSL)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
pkg_check_modules(PC_LIBJWT QUIET libjwt)
|
||||||
|
|
||||||
|
find_path(LIBJWT_INCLUDE_DIR
|
||||||
|
NAMES jwt.h
|
||||||
|
HINTS ${PC_LIBJWT_INCLUDEDIR} ${PC_LIBJWT_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(LIBJWT_LIBRARY
|
||||||
|
NAMES jwt libjwt liblibjwt
|
||||||
|
HINTS ${PC_LIBJWT_LIBDIR} ${PC_LIBJWT_LIBRARY_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(LibJWT
|
||||||
|
REQUIRED_VARS LIBJWT_INCLUDE_DIR LIBJWT_LIBRARY
|
||||||
|
)
|
||||||
|
|
||||||
|
if(LIBJWT_FOUND)
|
||||||
|
add_library(libjwt STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(libjwt PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${LIBJWT_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${LIBJWT_INCLUDE_DIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mark_as_advanced(LIBJWT_INCLUDE_DIR LIBJWT_LIBRARY)
|
|
@ -4,7 +4,7 @@
|
||||||
#if HAVE_LIBJWT
|
#if HAVE_LIBJWT
|
||||||
#include <jwt.h>
|
#include <jwt.h>
|
||||||
#else
|
#else
|
||||||
#include "jwt.h"
|
#include "jwt_cpp.h"
|
||||||
#endif
|
#endif
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#if HAVE_LIBCRYPTO
|
#if HAVE_LIBCRYPTO
|
||||||
|
@ -21,18 +21,19 @@ std::pair <std::string, unsigned int> verifyToken(std::string jwt_token_str, std
|
||||||
unsigned int token_issued_at = 0;
|
unsigned int token_issued_at = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
jwt_t *jwt = nullptr;
|
jwt_t *jwt = nullptr;
|
||||||
|
|
||||||
err = jwt_new(&jwt);
|
err = jwt_new(&jwt);
|
||||||
if( err ) {
|
if( err ) {
|
||||||
Error("Unable to Allocate JWT object");
|
Error("Unable to Allocate JWT object");
|
||||||
return std::make_pair("", 0);
|
return std::make_pair("", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = jwt_set_alg(jwt, JWT_ALG_HS256, key.c_str(), key.length());
|
err = jwt_set_alg(jwt, JWT_ALG_HS256, (const unsigned char*)key.c_str(), key.length());
|
||||||
if( err ) {
|
if( err ) {
|
||||||
jwt_free(jwt);
|
jwt_free(jwt);
|
||||||
Error("Error setting Algorithm for JWT decode");
|
Error("Error setting Algorithm for JWT decode");
|
||||||
return std::make_pair("", 0);
|
return std::make_pair("", 0);
|
||||||
s}
|
}
|
||||||
|
|
||||||
err = jwt_decode(&jwt, jwt_token_str.c_str(), nullptr, 0);
|
err = jwt_decode(&jwt, jwt_token_str.c_str(), nullptr, 0);
|
||||||
if( err ) {
|
if( err ) {
|
||||||
|
|
Loading…
Reference in New Issue