Skip to content

Commit f1164fa

Browse files
author
a.i.kuleshov
committed
feat: add query parameters support
1 parent d4beab9 commit f1164fa

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ngx_module_type=HTTP
22
ngx_addon_name=ngx_http_auth_jwt_module
33
ngx_module_name=$ngx_addon_name
4-
ngx_module_srcs="${ngx_addon_dir}/src/ngx_http_auth_jwt_binary_converters.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_header_processing.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_string.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_module.c"
4+
ngx_module_srcs="${ngx_addon_dir}/src/ngx_http_auth_jwt_binary_converters.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_header_processing.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_string.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_module.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_query_processing.c"
55
ngx_module_libs="-ljansson -ljwt -lm"
66

77
. auto/module

src/ngx_http_auth_jwt_module.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "ngx_http_auth_jwt_header_processing.h"
1818
#include "ngx_http_auth_jwt_binary_converters.h"
19+
#include "ngx_http_auth_jwt_query_processing.h"
1920
#include "ngx_http_auth_jwt_string.h"
2021

2122
#include <stdio.h>
@@ -513,7 +514,7 @@ static char * getJwt(ngx_http_request_t *r, ngx_str_t auth_jwt_validation_type)
513514
ngx_table_elt_t *authorizationHeader;
514515
char* jwtPtr = NULL;
515516
ngx_str_t jwtCookieVal;
516-
//ngx_str_t jwtQueryVal;
517+
ngx_str_t jwtQueryVal;
517518
ngx_int_t n;
518519
ngx_int_t bearer_length;
519520
ngx_str_t authorizationHeaderStr;
@@ -543,7 +544,23 @@ static char * getJwt(ngx_http_request_t *r, ngx_str_t auth_jwt_validation_type)
543544
}
544545
else if (auth_jwt_validation_type.len > sizeof("QUERY=") && ngx_strncmp(auth_jwt_validation_type.data, "QUERY=", sizeof("QUERY=") - 1)==0)
545546
{
546-
ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0, "auth_jwt_validation_type.len %d", auth_jwt_validation_type.len);
547+
auth_jwt_validation_type.data += sizeof("QUERY=") - 1;
548+
auth_jwt_validation_type.len -= sizeof("QUERY=") - 1;
549+
550+
ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0, "http thread: \"%V?%V\"", &r->uri, &r->args);
551+
552+
553+
// get value from query
554+
n = get_value_from_query(r, &auth_jwt_validation_type, &jwtQueryVal);
555+
if (n != NGX_ERROR)
556+
{
557+
jwtPtr = ngx_str_t_to_char_ptr(r->pool, jwtQueryVal);
558+
}
559+
else
560+
{
561+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "error get value from query param");
562+
}
563+
547564
}
548565
else if (auth_jwt_validation_type.len > sizeof("COOKIE=") && ngx_strncmp(auth_jwt_validation_type.data, "COOKIE=", sizeof("COOKIE=") - 1)==0)
549566
{

src/ngx_http_auth_jwt_query_processing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
ngx_int_t get_value_from_query(ngx_http_request_t *r, ngx_str_t *key, ngx_str_t *value)
77
{
8-
return
8+
return NGX_ERROR;
99
}

0 commit comments

Comments
 (0)