@@ -29,7 +29,8 @@ typedef struct {
29
29
ngx_flag_t auth_jwt_redirect ;
30
30
ngx_str_t auth_jwt_validation_type ;
31
31
ngx_str_t auth_jwt_algorithm ;
32
- ngx_flag_t auth_jwt_filekey ;
32
+ ngx_flag_t auth_jwt_use_keyfile ;
33
+ ngx_str_t auth_jwt_keyfile_path ;
33
34
ngx_flag_t auth_jwt_validate_email ;
34
35
35
36
} ngx_http_auth_jwt_loc_conf_t ;
@@ -63,11 +64,18 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
63
64
offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_enabled ),
64
65
NULL },
65
66
66
- { ngx_string ("auth_jwt_filekey " ),
67
+ { ngx_string ("auth_jwt_use_keyfile " ),
67
68
NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_FLAG ,
68
69
ngx_conf_set_flag_slot ,
69
70
NGX_HTTP_LOC_CONF_OFFSET ,
70
- offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_filekey ),
71
+ offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_use_keyfile ),
72
+ NULL },
73
+
74
+ { ngx_string ("auth_jwt_keyfile_path" ),
75
+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_TAKE1 ,
76
+ ngx_conf_set_str_slot ,
77
+ NGX_HTTP_LOC_CONF_OFFSET ,
78
+ offsetof(ngx_http_auth_jwt_loc_conf_t , auth_jwt_keyfile_path ),
71
79
NULL },
72
80
73
81
{ ngx_string ("auth_jwt_redirect" ),
@@ -190,9 +198,9 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
190
198
{
191
199
// in this case, 'Binary' is a misnomer, as it is the public key string itself
192
200
ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "failed to find a jwt" );
193
- if (jwtcf -> auth_jwt_filekey == 1 )
201
+ if (jwtcf -> auth_jwt_use_keyfile == 1 )
194
202
{
195
- FILE * file = fopen (KEY_FILE_PATH , "rb" );
203
+ FILE * file = fopen (( const char * ) jwtcf -> auth_jwt_keyfile_path . data , "rb" );
196
204
197
205
// Check if file exists or is correctly opened
198
206
if (file == NULL )
@@ -423,7 +431,7 @@ ngx_http_auth_jwt_create_loc_conf(ngx_conf_t *cf)
423
431
conf -> auth_jwt_enabled = (ngx_flag_t ) - 1 ;
424
432
conf -> auth_jwt_redirect = (ngx_flag_t ) - 1 ;
425
433
conf -> auth_jwt_validate_email = (ngx_flag_t ) - 1 ;
426
- conf -> auth_jwt_filekey = (ngx_flag_t ) - 1 ;
434
+ conf -> auth_jwt_use_keyfile = (ngx_flag_t ) - 1 ;
427
435
428
436
ngx_conf_log_error (NGX_LOG_DEBUG , cf , 0 , "Created Location Configuration" );
429
437
@@ -441,6 +449,7 @@ ngx_http_auth_jwt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
441
449
ngx_conf_merge_str_value (conf -> auth_jwt_key , prev -> auth_jwt_key , "" );
442
450
ngx_conf_merge_str_value (conf -> auth_jwt_validation_type , prev -> auth_jwt_validation_type , "" );
443
451
ngx_conf_merge_str_value (conf -> auth_jwt_algorithm , prev -> auth_jwt_algorithm , "HS256" );
452
+ ngx_conf_merge_str_value (conf -> auth_jwt_keyfile_path , prev -> auth_jwt_keyfile_path , KEY_FILE_PATH );
444
453
ngx_conf_merge_off_value (conf -> auth_jwt_validate_email , prev -> auth_jwt_validate_email , 1 );
445
454
446
455
if (conf -> auth_jwt_enabled == ((ngx_flag_t ) - 1 ))
@@ -453,9 +462,9 @@ ngx_http_auth_jwt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
453
462
conf -> auth_jwt_redirect = (prev -> auth_jwt_redirect == ((ngx_flag_t ) - 1 )) ? 0 : prev -> auth_jwt_redirect ;
454
463
}
455
464
456
- if (conf -> auth_jwt_filekey == ((ngx_flag_t ) - 1 ))
465
+ if (conf -> auth_jwt_use_keyfile == ((ngx_flag_t ) - 1 ))
457
466
{
458
- conf -> auth_jwt_filekey = (prev -> auth_jwt_filekey == ((ngx_flag_t ) - 1 )) ? 0 : prev -> auth_jwt_filekey ;
467
+ conf -> auth_jwt_use_keyfile = (prev -> auth_jwt_use_keyfile == ((ngx_flag_t ) - 1 )) ? 0 : prev -> auth_jwt_use_keyfile ;
459
468
}
460
469
461
470
return NGX_CONF_OK ;
0 commit comments