Skip to content

Commit b888c93

Browse files
update to support NGINX 1.23.0+ (#89)
1 parent 697551d commit b888c93

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ RUN <<`
88
apt-get update
99
apt-get install -y curl build-essential
1010
`
11+
12+
1113
FROM ngx_http_auth_jwt_builder_base as ngx_http_auth_jwt_builder_module
1214
LABEL stage=ngx_http_auth_jwt_builder
1315
ENV LD_LIBRARY_PATH=/usr/local/lib
@@ -29,7 +31,17 @@ tar -xzf nginx-${NGINX_VERSION}.tar.gz --strip-components 1 -C nginx
2931
`
3032
WORKDIR /root/build/nginx
3133
RUN <<`
32-
./configure --with-debug --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module
34+
BUILD_FLAGS=''
35+
MAJ=$(echo ${NGINX_VERSION} | cut -f1 -d.)
36+
MIN=$(echo ${NGINX_VERSION} | cut -f2 -d.)
37+
REV=$(echo ${NGINX_VERSION} | cut -f3 -d.)
38+
39+
# NGINX 1.23.0+ changes `cookies` to `cookie`
40+
if [ "${MAJ}" -gt 1 ] || [ "${MAJ}" -eq 1 -a "${MIN}" -ge 23 ]; then
41+
BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'"
42+
fi
43+
44+
./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module ${BUILD_FLAGS}
3345
make modules
3446
`
3547

src/ngx_http_auth_jwt_module.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ngx_http_auth_jwt_string.h"
2020

2121
#include <stdio.h>
22+
#include <stdbool.h>
2223

2324
typedef struct
2425
{
@@ -639,15 +640,25 @@ static char *get_jwt(ngx_http_request_t *r, ngx_str_t validation_type)
639640
}
640641
else if (validation_type.len > sizeof("COOKIE=") && ngx_strncmp(validation_type.data, "COOKIE=", sizeof("COOKIE=") - 1) == 0)
641642
{
642-
ngx_int_t n;
643+
bool has_cookie = false;
643644
ngx_str_t jwtCookieVal;
644645

645646
validation_type.data += sizeof("COOKIE=") - 1;
646647
validation_type.len -= sizeof("COOKIE=") - 1;
647648

648-
n = ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &validation_type, &jwtCookieVal);
649+
#ifndef NGX_LINKED_LIST_COOKIES
650+
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &validation_type, &jwtCookieVal) != NGX_DECLINED)
651+
{
652+
has_cookie = true;
653+
}
654+
#else
655+
if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &validation_type, &jwtCookieVal) != NULL)
656+
{
657+
has_cookie = true;
658+
}
659+
#endif
649660

650-
if (n != NGX_DECLINED)
661+
if (has_cookie == true)
651662
{
652663
jwtPtr = ngx_str_t_to_char_ptr(r->pool, jwtCookieVal);
653664
}

0 commit comments

Comments
 (0)