Skip to content

Commit 270b029

Browse files
cleanup
1 parent ed4f416 commit 270b029

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/ngx_http_auth_jwt_module.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
179179
}
180180

181181
jwtCookieValChrPtr = getJwt(r, jwtcf->auth_jwt_validation_type);
182+
182183
if (jwtCookieValChrPtr == NULL)
183184
{
184185
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to find a jwt");
@@ -188,6 +189,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
188189
// convert key from hex to binary, if a symmetric key
189190

190191
auth_jwt_algorithm = jwtcf->auth_jwt_algorithm;
192+
191193
if (auth_jwt_algorithm.len == 0 || (auth_jwt_algorithm.len == sizeof("HS256") - 1 && ngx_strncmp(auth_jwt_algorithm.data, "HS256", sizeof("HS256") - 1)==0))
192194
{
193195
keylen = jwtcf->auth_jwt_key.len / 2;
@@ -222,6 +224,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
222224

223225
// validate the jwt
224226
jwtParseReturnCode = jwt_decode(&jwt, jwtCookieValChrPtr, keyBinary, keylen);
227+
225228
if (jwtParseReturnCode != 0)
226229
{
227230
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to parse jwt");
@@ -230,6 +233,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
230233

231234
// validate the algorithm
232235
alg = jwt_get_alg(jwt);
236+
233237
if (alg != JWT_ALG_HS256 && alg != JWT_ALG_RS256)
234238
{
235239
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "invalid algorithm in jwt %d", alg);
@@ -239,6 +243,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
239243
// validate the exp date of the JWT
240244
exp = (time_t)jwt_get_grant_int(jwt, "exp");
241245
now = time(NULL);
246+
242247
if (exp < now)
243248
{
244249
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "the jwt has expired");
@@ -279,12 +284,10 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
279284
}
280285

281286
jwt_free(jwt);
282-
283287

284288
return NGX_OK;
285289

286290
redirect:
287-
288291
if (jwt)
289292
{
290293
jwt_free(jwt);
@@ -314,7 +317,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
314317
uintptr_t escaped_len;
315318

316319
loginlen = jwtcf->auth_jwt_loginurl.len;
317-
318320
scheme = (r->connection->ssl) ? "https" : "http";
319321
server = r->headers_in.server;
320322

@@ -329,15 +331,11 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
329331
uri.data = ngx_palloc(r->pool, request_uri_var->len);
330332
uri.len = request_uri_var->len;
331333
ngx_memcpy(uri.data, request_uri_var->data, request_uri_var->len);
332-
333-
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "found uri with querystring %s", ngx_str_t_to_char_ptr(r->pool, uri));
334334
}
335335
else
336336
{
337337
// fallback to the querystring without params
338338
uri = r->uri;
339-
340-
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "fallback to querystring without params");
341339
}
342340

343341
// escape the URI
@@ -361,8 +359,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
361359
ngx_memcpy(return_url+return_url_idx, uri_escaped.data, uri_escaped.len);
362360
return_url_idx += uri_escaped.len;
363361
r->headers_out.___location->value.data = (u_char *)return_url;
364-
365-
// ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "return_url: %s", ngx_str_t_to_char_ptr(r->pool, r->headers_out.___location->value));
366362
}
367363
else
368364
{

test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ test_jwt () {
1111
local extra=$4
1212

1313
cmd="curl -X GET -o /dev/null --silent --head --write-out '%{http_code}' http://nginx:8000$path -H 'cache-control: no-cache' $extra"
14-
15-
1614
test=$( eval ${cmd} )
17-
if [ "$test" -eq "$expect" ];then
15+
16+
if [ "$test" -eq "$expect" ]; then
1817
echo -e "${GREEN}${name}: passed (${test})${NONE}";
1918
else
2019
echo -e "${RED}${name}: failed (${test})${NONE}";

0 commit comments

Comments
 (0)