Skip to content

Commit 9908b1b

Browse files
committed
Revert "Merge pull request TeslaGov#54 from TeslaGov/pr/42"
This reverts commit f6e8452, reversing changes made to bf24cbe.
1 parent f542086 commit 9908b1b

File tree

3 files changed

+168
-54
lines changed

3 files changed

+168
-54
lines changed

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,13 @@ This module requires several new `nginx.conf` directives,
4040
which can be specified in on the `main` `server` or `___location` level.
4141

4242
```
43-
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF";
43+
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF"; # see docs for format based on algorithm
44+
auth_jwt_loginurl "https://yourdomain.com/loginpage";
4445
auth_jwt_enabled on;
4546
auth_jwt_algorithm HS256; # or RS256
4647
auth_jwt_validate_email on; # or off
4748
```
4849

49-
So, a typical use would be to specify the key on the main level and then only
50-
turn on the locations that you want to secure (not the login page). Unauthorized
51-
requests are given 401 "Unauthorized" responses, you can redirect them with the
52-
nginx's `error_page` directive.
53-
54-
```
55-
___location @login_redirect {
56-
allow all;
57-
return 302 https://yourdomain.com/loginpage;
58-
}
59-
60-
___location /secure-___location/ {
61-
auth_jwt_enabled on;
62-
error_page 401 = @login_redirect;
63-
}
64-
```
65-
6650
The default algorithm is 'HS256', for symmetric key validation. When using HS256, the value for `auth_jwt_key` should be specified in binhex format. It is recommended to use at least 256 bits of data (32 pairs of hex characters or 64 characters in total) as in the example above. Note that using more than 512 bits will not increase the security. For key guidelines please see NIST Special Publication 800-107 Recommendation for Applications Using Approved Hash Algorithms, Section 5.3.2 The HMAC Key.
6751

6852
The configuration also supports the `auth_jwt_algorithm` 'RS256', for RSA 256-bit public key validation. If using "auth_jwt_algorithm RS256;", then the `auth_jwt_key` field must be set to your public key.
@@ -80,7 +64,15 @@ oQIDAQAB
8064
-----END PUBLIC KEY-----";
8165
```
8266

83-
This module supports two ways of presenting the token.
67+
A typical use would be to specify the key and loginurl on the main level
68+
and then only turn on the locations that you want to secure (not the login page).
69+
Unauthorized requests are given 302 "Moved Temporarily" responses with a ___location of the specified loginurl.
70+
71+
```
72+
auth_jwt_redirect off;
73+
```
74+
If you prefer to return 401 Unauthorized, you may turn `auth_jwt_redirect` off.
75+
8476
```
8577
auth_jwt_validation_type AUTHORIZATION;
8678
auth_jwt_validation_type COOKIE=rampartjwt;

resources/test-jwt-nginx.conf

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
server {
22
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF";
3-
set $auth_jwt_login_url "https://teslagov.com";
3+
auth_jwt_loginurl "https://teslagov.com";
44
auth_jwt_enabled off;
5+
auth_jwt_redirect on;
56

67
listen 8000;
78
server_name localhost;
89

9-
root /usr/share/nginx/html;
10-
index index.html index.htm;
11-
12-
___location @login_redirect {
13-
return 302 $auth_jwt_login_url?redirect=$request_uri&$args;
14-
}
15-
1610
___location ~ ^/secure-no-redirect/ {
17-
rewrite "" / break;
1811
auth_jwt_enabled on;
12+
auth_jwt_redirect off;
13+
root /usr/share/nginx;
14+
index index.html index.htm;
1915
}
2016

2117
___location ~ ^/secure/ {
22-
rewrite "" / break;
2318
auth_jwt_enabled on;
2419
auth_jwt_validation_type COOKIE=rampartjwt;
25-
error_page 401 = @login_redirect;
20+
root /usr/share/nginx;
21+
index index.html index.htm;
2622
}
2723

2824
___location ~ ^/secure-auth-header/ {
29-
rewrite "" / break;
3025
auth_jwt_enabled on;
31-
error_page 401 = @login_redirect;
26+
root /usr/share/nginx;
27+
index index.html index.htm;
3228
}
3329

3430
___location ~ ^/secure-rs256/ {
35-
rewrite "" / break;
3631
auth_jwt_enabled on;
3732
auth_jwt_validation_type COOKIE=rampartjwt;
3833
auth_jwt_algorithm RS256;
@@ -45,7 +40,13 @@ ZQX0miOXXWdkQvWTZFXhmsFCmJLE67oQFSar4hzfAaCulaMD+b3Mcsjlh0yvSq7g
4540
K49NdYBvFP+hNVEoeZzJz5K/nd6C35IX0t2bN5CVXchUFmaUMYk2iPdhXdsC720t
4641
BwIDAQAB
4742
-----END PUBLIC KEY-----";
43+
root /usr/share/nginx;
44+
index index.html index.htm;
4845
}
4946

50-
___location / {}
47+
___location / {
48+
root /usr/share/nginx/html;
49+
index index.html index.htm;
50+
}
5151
}
52+

0 commit comments

Comments
 (0)