Skip to content

Commit 4822be3

Browse files
committed
Updated README.
Rearranged some code.
1 parent da07bc2 commit 4822be3

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This module requires several new nginx.conf directives, which can be specified i
1313
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF";
1414
auth_jwt_loginurl "https://yourdomain.com/loginpage";
1515
auth_jwt_enabled on;
16+
auth_jwt_algorithm HS256; # or RS256
17+
auth_jwt_validate_email on; # or off
1618
```
1719

1820
So, a typical use would be to specify the key and loginurl on the main level and then only turn on the locations that you want to secure (not the login page). Unauthorized requests are given 302 "Moved Temporarily" responses with a ___location of the specified loginurl.
@@ -28,6 +30,34 @@ auth_jwt_validation_type COOKIE=rampartjwt;
2830
```
2931
By default the authorization header is used to provide a JWT for validation. However, you may use the `auth_jwt_validation_type` configuration to specify the name of a cookie that provides the JWT.
3032

33+
34+
35+
The default algorithm is 'HS256', for symmetric key validation. Also supported is 'RS256', for RSA 256-bit public key validation.
36+
37+
If using "auth_jwt_algorithm RS256;", then the 'auth_jwt_key' field must be set to your public key. That is the public key, rather than a PEM certificate. I.e.:
38+
39+
```
40+
auth_jwt_key "-----BEGIN PUBLIC KEY-----
41+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0aPPpS7ufs0bGbW9+OFQ
42+
RvJwb58fhi2BuHMd7Ys6m8D1jHW/AhDYrYVZtUnA60lxwSJ/ZKreYOQMlNyZfdqA
43+
rhYyyUkedDn8e0WsDvH+ocY0cMcxCCN5jItCwhIbIkTO6WEGrDgWTY57UfWDqbMZ
44+
4lMn42f77OKFoxsOA6CVvpsvrprBPIRPa25H2bJHODHEtDr/H519Y681/eCyeQE/
45+
1ibKL2cMN49O7nRAAaUNoFcO89Uc+GKofcad1TTwtTIwmSMbCLVkzGeExBCrBTQo
46+
wO6AxLijfWV/JnVxNMUiobiKGc/PP6T5PI70Uv67Y4FzzWTuhqmREb3/BlcbPwtM
47+
oQIDAQAB
48+
-----END PUBLIC KEY-----";
49+
```
50+
51+
52+
53+
By default, the module will attempt to validate the email address field of the JWT, then set the x-email header of the session, and will log an error if it isn't found. To disable this behavior, for instance if you are using a different user identifier property such as 'sub', set:
54+
55+
```
56+
auth_jwt_validate_email off;
57+
```
58+
59+
60+
3161
The Dockerfile builds all of the dependencies as well as the module, downloads a binary version of nginx, and runs the module as a dynamic module.
3262

3363
Have a look at build.sh, which creates the docker image and container and executes some test requests to illustrate that some pages are secured by the module and requre a valid JWT.

src/ngx_http_auth_jwt_module.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ typedef struct {
2323
ngx_str_t auth_jwt_key;
2424
ngx_flag_t auth_jwt_enabled;
2525
ngx_flag_t auth_jwt_redirect;
26-
ngx_flag_t auth_jwt_validate_email;
2726
ngx_str_t auth_jwt_validation_type;
2827
ngx_str_t auth_jwt_algorithm;
28+
ngx_flag_t auth_jwt_validate_email;
2929

3030
} ngx_http_auth_jwt_loc_conf_t;
3131

@@ -65,13 +65,6 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
6565
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_redirect),
6666
NULL },
6767

68-
{ ngx_string("auth_jwt_validate_email"),
69-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
70-
ngx_conf_set_flag_slot,
71-
NGX_HTTP_LOC_CONF_OFFSET,
72-
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_validate_email),
73-
NULL },
74-
7568
{ ngx_string("auth_jwt_validation_type"),
7669
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
7770
ngx_conf_set_str_slot,
@@ -86,6 +79,13 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
8679
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_algorithm),
8780
NULL },
8881

82+
{ ngx_string("auth_jwt_validate_email"),
83+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
84+
ngx_conf_set_flag_slot,
85+
NGX_HTTP_LOC_CONF_OFFSET,
86+
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_validate_email),
87+
NULL },
88+
8989
ngx_null_command
9090
};
9191

@@ -213,7 +213,6 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
213213
set_custom_header_in_headers_out(r, &useridHeaderName, &sub_t);
214214
}
215215

216-
// if (jwtcf->auth_jwt_validate_email == NULL || jwtcf->auth_jwt_validate_email == 1)
217216
if (jwtcf->auth_jwt_validate_email == 1)
218217
{
219218
email = jwt_get_grant(jwt, "emailAddress");

0 commit comments

Comments
 (0)