@@ -179,6 +179,7 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
179
179
}
180
180
181
181
jwtCookieValChrPtr = getJwt (r , jwtcf -> auth_jwt_validation_type );
182
+
182
183
if (jwtCookieValChrPtr == NULL )
183
184
{
184
185
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)
188
189
// convert key from hex to binary, if a symmetric key
189
190
190
191
auth_jwt_algorithm = jwtcf -> auth_jwt_algorithm ;
192
+
191
193
if (auth_jwt_algorithm .len == 0 || (auth_jwt_algorithm .len == sizeof ("HS256" ) - 1 && ngx_strncmp (auth_jwt_algorithm .data , "HS256" , sizeof ("HS256" ) - 1 )== 0 ))
192
194
{
193
195
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)
222
224
223
225
// validate the jwt
224
226
jwtParseReturnCode = jwt_decode (& jwt , jwtCookieValChrPtr , keyBinary , keylen );
227
+
225
228
if (jwtParseReturnCode != 0 )
226
229
{
227
230
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)
230
233
231
234
// validate the algorithm
232
235
alg = jwt_get_alg (jwt );
236
+
233
237
if (alg != JWT_ALG_HS256 && alg != JWT_ALG_RS256 )
234
238
{
235
239
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)
239
243
// validate the exp date of the JWT
240
244
exp = (time_t )jwt_get_grant_int (jwt , "exp" );
241
245
now = time (NULL );
246
+
242
247
if (exp < now )
243
248
{
244
249
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)
279
284
}
280
285
281
286
jwt_free (jwt );
282
-
283
287
284
288
return NGX_OK ;
285
289
286
290
redirect :
287
-
288
291
if (jwt )
289
292
{
290
293
jwt_free (jwt );
@@ -314,7 +317,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
314
317
uintptr_t escaped_len ;
315
318
316
319
loginlen = jwtcf -> auth_jwt_loginurl .len ;
317
-
318
320
scheme = (r -> connection -> ssl ) ? "https" : "http" ;
319
321
server = r -> headers_in .server ;
320
322
@@ -329,15 +331,11 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
329
331
uri .data = ngx_palloc (r -> pool , request_uri_var -> len );
330
332
uri .len = request_uri_var -> len ;
331
333
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));
334
334
}
335
335
else
336
336
{
337
337
// fallback to the querystring without params
338
338
uri = r -> uri ;
339
-
340
- // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "fallback to querystring without params");
341
339
}
342
340
343
341
// escape the URI
@@ -361,8 +359,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
361
359
ngx_memcpy (return_url + return_url_idx , uri_escaped .data , uri_escaped .len );
362
360
return_url_idx += uri_escaped .len ;
363
361
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));
366
362
}
367
363
else
368
364
{
0 commit comments