-
Notifications
You must be signed in to change notification settings - Fork 127
Feature/support token in query string #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
santerioksanen
wants to merge
10
commits into
TeslaGov:master
Choose a base branch
from
santerioksanen:feature/support-token-in-query-string
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5f33f6c
Add functionality and tests for providing jwt-tokens in query-string
d21d408
Add description to readme
8702e17
Update README.md
santerioksanen d00aa5b
Update README with QUERYSTRING information
santerioksanen affce53
Apply styling changes
santerioksanen 7dd8b00
Apply styling changes per code-review
6be0086
Add test-cases, change tests to use token instead of jwt-token
df039e2
Change prefix char pointers to char arrays
17fbdc0
Remove redundant else
ed421fa
Remove ngx_pfree for args
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ngx_module_type=HTTP | ||
ngx_addon_name=ngx_http_auth_jwt_module | ||
ngx_module_name=$ngx_addon_name | ||
ngx_module_srcs="${ngx_addon_dir}/src/arrays.c ${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_module_srcs="${ngx_addon_dir}/src/arrays.c ${ngx_addon_dir}/src/ngx_http_auth_jwt_args_processing.c ${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_module_libs="-ljansson -ljwt -lm" | ||
|
||
. auto/module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "ngx_http_auth_jwt_args_processing.h" | ||
|
||
u_char *create_args_without_token( | ||
ngx_pool_t *pool, | ||
ngx_str_t *args, | ||
size_t token_key_start, | ||
size_t token_end, | ||
size_t *write_args_len | ||
) { | ||
/* Creates a new version of args without token present. | ||
Writes length of new args to *write_args_len | ||
*/ | ||
*write_args_len = args->len - token_end + token_key_start; | ||
|
||
u_char *args_ptr = ngx_palloc(pool, *write_args_len); | ||
|
||
if (args_ptr == NULL) return NULL; | ||
|
||
if (token_key_start > 0) { | ||
ngx_memcpy(args_ptr, args->data, token_key_start); | ||
} | ||
if (token_end < (args->len - 1)) { | ||
ngx_memcpy( | ||
args_ptr + token_key_start, | ||
args->data + token_end, | ||
*write_args_len - token_key_start | ||
); | ||
} | ||
|
||
return args_ptr; | ||
} | ||
santerioksanen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bool search_token_from_args( | ||
const ngx_str_t *jwt_location, | ||
const ngx_str_t *args, | ||
size_t *write_to_token_key_start, | ||
size_t *write_to_token_value_start, | ||
size_t *write_to_token_end | ||
) { | ||
/* Tries to extract token from query string. Returns true if found, false otherwise. | ||
|
||
Searches for the string contained in *jwt_location in *args. If it finds the token | ||
in question it writes the location of the start of key to *write_to_token_key_start, | ||
start of token itself to *write_to_token_value_start and end of token to *write_to_token_end. | ||
*/ | ||
size_t i = 0, j = 0; | ||
size_t max_i = args->len > jwt_location->len ? args->len - jwt_location->len : 0; | ||
|
||
while (i < max_i) { | ||
j = 0; | ||
if (i == 0 || *(args->data + i - 1) == '&') { | ||
while (j < jwt_location->len && *(args->data + i + j) == *(jwt_location->data + j)) { | ||
if (j == (jwt_location->len - 1)) { | ||
*write_to_token_key_start = i; | ||
i++; | ||
if (i >= max_i || *(args->data + i + j) != '=') { | ||
// key doesn't match | ||
break; | ||
} | ||
*write_to_token_value_start = i + j + 1; | ||
while (i < args->len && *(args->data + i) != '&') { | ||
i++; | ||
} | ||
*write_to_token_end = i; | ||
return true; | ||
} | ||
j++; | ||
} | ||
} | ||
i++; | ||
} | ||
return false; | ||
} | ||
santerioksanen marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _NGX_HTTP_AUTH_JWT_ARGS_PROCESSING_H | ||
#define _NGX_HTTP_AUTH_JWT_ARGS_PROCESSING_H | ||
|
||
#include <ngx_core.h> | ||
#include <stdbool.h> | ||
|
||
u_char *create_args_without_token( | ||
ngx_pool_t *pool, | ||
ngx_str_t *args, | ||
size_t token_key_start, | ||
size_t token_end, | ||
size_t *write_mutated_args_len | ||
); | ||
|
||
bool search_token_from_args( | ||
const ngx_str_t *jwt_location, | ||
const ngx_str_t *args, | ||
size_t *write_to_token_key_start, | ||
size_t *write_to_token_value_start, | ||
size_t *write_to_token_end | ||
); | ||
|
||
#endif /* _NGX_HTTP_AUTH_JWT_ARGS_PROCESSING_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.