@@ -14,6 +14,7 @@ typedef struct {
14
14
ngx_str_t auth_jwt_loginurl ;
15
15
ngx_str_t auth_jwt_key ;
16
16
ngx_flag_t auth_jwt_enabled ;
17
+ ngx_flag_t auth_jwt_redirect ;
17
18
} ngx_http_auth_jwt_loc_conf_t ;
18
19
19
20
static ngx_int_t ngx_http_auth_jwt_init (ngx_conf_t * cf );
@@ -48,6 +49,13 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
48
49
offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_enabled ),
49
50
NULL },
50
51
52
+ { ngx_string ("auth_jwt_redirect" ),
53
+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_FLAG ,
54
+ ngx_conf_set_flag_slot ,
55
+ NGX_HTTP_LOC_CONF_OFFSET ,
56
+ offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_redirect ),
57
+ NULL },
58
+
51
59
ngx_null_command
52
60
};
53
61
@@ -272,7 +280,14 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
272
280
r -> headers_out .___location -> value .data = jwtcf -> auth_jwt_loginurl .data ;
273
281
}
274
282
275
- return NGX_HTTP_MOVED_TEMPORARILY ;
283
+ if (jwtcf -> auth_jwt_redirect )
284
+ {
285
+ return NGX_HTTP_MOVED_TEMPORARILY ;
286
+ }
287
+ else
288
+ {
289
+ return NGX_HTTP_UNAUTHORIZED ;
290
+ }
276
291
}
277
292
278
293
@@ -308,6 +323,7 @@ ngx_http_auth_jwt_create_loc_conf(ngx_conf_t *cf)
308
323
309
324
// set the flag to unset
310
325
conf -> auth_jwt_enabled = (ngx_flag_t ) - 1 ;
326
+ conf -> auth_jwt_redirect = (ngx_flag_t ) - 1 ;
311
327
312
328
ngx_conf_log_error (NGX_LOG_DEBUG , cf , 0 , "Created Location Configuration" );
313
329
@@ -324,11 +340,15 @@ ngx_http_auth_jwt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
324
340
ngx_conf_merge_str_value (conf -> auth_jwt_loginurl , prev -> auth_jwt_loginurl , "" );
325
341
ngx_conf_merge_str_value (conf -> auth_jwt_key , prev -> auth_jwt_key , "" );
326
342
327
-
328
343
if (conf -> auth_jwt_enabled == ((ngx_flag_t ) - 1 ))
329
344
{
330
345
conf -> auth_jwt_enabled = (prev -> auth_jwt_enabled == ((ngx_flag_t ) - 1 )) ? 0 : prev -> auth_jwt_enabled ;
331
346
}
347
+
348
+ if (conf -> auth_jwt_redirect == ((ngx_flag_t ) - 1 ))
349
+ {
350
+ conf -> auth_jwt_redirect = (prev -> auth_jwt_redirect == ((ngx_flag_t ) - 1 )) ? 0 : prev -> auth_jwt_redirect ;
351
+ }
332
352
333
353
ngx_conf_log_error (NGX_LOG_DEBUG , cf , 0 , "Merged Location Configuration" );
334
354
0 commit comments