Skip to content

Commit 5f08e17

Browse files
authored
Update README.md
1 parent bd047fd commit 5f08e17

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@ This is an NGINX module to check for a valid JWT and proxy to an upstream server
44
# Build Requirements
55
This module depends on the [JWT C Library](https://github.com/benmcollins/libjwt)
66

7+
Unfortunately, this library cannot handle grants that are not strings. In the JWT Spec, some grants, such as "exp" and "iat" are supposed to be stored as integers, not strings. If the JWT is created by another library and an exp is set as an integer, this library will return NULL when you try to get that grant. There is a pull request by another person to address this issue, but it has been on hold for months. I have patched the library myself.
8+
9+
I added these lines to jwt.h
10+
11+
```
12+
const char *jwt_get_grant(jwt_t *jwt, const char *grant);
13+
int jwt_get_grant_int(jwt_t *jwt, const char *grant);
14+
```
15+
16+
I added these lines to jwt.c
17+
18+
```
19+
static int get_js_int(json_t *js, const char *key)
20+
{
21+
int val = -1;
22+
json_t *js_val;
23+
24+
js_val = json_object_get(js, key);
25+
if (js_val)
26+
val = (int)json_integer_value(js_val);
27+
28+
return val;
29+
return 0;
30+
}
31+
32+
int jwt_get_grant_int(jwt_t *jwt, const char *grant)
33+
{
34+
if (!jwt || !grant || !strlen(grant)) {
35+
errno = EINVAL;
36+
return 0;
37+
}
38+
39+
errno = 0;
40+
41+
return get_js_int(jwt->grants, grant);
42+
}
43+
```
44+
45+
746
Transitively, that library depends on a JSON Parser called [Jansson](https://github.com/akheron/jansson) as well as OpenSSL
847

948
# NGINX Directives
@@ -53,13 +92,17 @@ To compile libjwt on my mac I had to edit the `CMakeLists.txt` file and add this
5392
include_directories(/usr/local/Cellar/openssl/1.0.2h_1/include/)
5493
```
5594

56-
To compile libjwt on my CentOS VM I had to edit the CMakeLists.txt file and add this flag to the list of CMAKE_C_FLAGS:
95+
To compile libjwt on my CentOS VM I had to edit the `CMakeLists.txt` file and add this flag to the list of `CMAKE_C_FLAGS`:
5796

5897
```
5998
-std=gnu99
6099
```
61100

101+
Edit `include/jwt.h` and `libjwt/jwt.c` according to my comments above.
102+
62103
```
104+
vi include/jwt.h
105+
vi libjwt/jwt.c
63106
vi CMakeLists.txt
64107
cmake .
65108
make jwt_static

0 commit comments

Comments
 (0)