You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-3
Original file line number
Diff line number
Diff line change
@@ -30,13 +30,31 @@ Subsequent requests to protected resources are authenticated by exchanging the s
30
30
31
31
For more information on OpenID Connect and JWT validation with NGINX Plus, see [Authenticating Users to Existing Applications with OpenID Connect and NGINX Plus](https://www.nginx.com/blog/authenticating-users-existing-applications-openid-connect-nginx-plus/).
32
32
33
+
### Access Tokens
34
+
35
+
The [access tokens](https://openid.net/specs/openid-connect-core-1_0.html#AccessTokenDisclosure) are used in token-based authentication to allow OIDC client to access a protected resource on behalf of the user. NGINX Plus receives an access token after a user successfully authenticates and authorizes access, when storing it in the key-value store. NGINX Plus can pass that token on the HTTP Authorization header as a [Bearer token](https://oauth.net/2/bearer-tokens/) for every request that is sent to the downstream application.
36
+
37
+
> **Note:** NGINX Plus does not verify the validity of the access token on each request, as we do with the ID token, so we cannot know if the access token has already expired or not. So, if access token lifetime is less than the ID token lifetime, you have to use the `proxy_intercept_errors on` directive, which will intercept and redirect "401 Unauthorized" responses to NGINX in order to refresh the access token.
38
+
39
+
```nginx
40
+
# Bearer token is uses to authorize NGINX to access protected backend
# Intercept and redirect "401 Unauthorized" proxied responses to nginx
44
+
# for processing with the error_page directive. Necessary if Access Token
45
+
# can expire before ID Token.
46
+
proxy_intercept_errors on;
47
+
48
+
proxy_pass http://my_backend; # The backend site/app
49
+
```
50
+
33
51
### Refresh Tokens
34
52
35
53
If a [refresh token](https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokens) was received from the IdP then it is also stored in the key-value store. When validation of the ID Token fails (typically upon expiry) then NGINX Plus sends the refresh token to the IdP. If the user's session is still valid at the IdP then a new ID token is received, validated, and updated in the key-value store. The refresh process is seamless to the client.
36
54
37
55
### Logout
38
56
39
-
Requests made to the `/logout` location invalidate both the ID token and refresh token by erasing them from the key-value store. Therefore, subsequent requests to protected resources will be treated as a first-time request and send the client to the IdP for authentication. Note that the IdP may issue cookies such that an authenticated session still exists at the IdP.
57
+
Requests made to the `/logout` location invalidate both the ID token, access token and refresh token by erasing them from the key-value store. Therefore, subsequent requests to protected resources will be treated as a first-time request and send the client to the IdP for authentication. Note that the IdP may issue cookies such that an authenticated session still exists at the IdP.
40
58
41
59
### Multiple IdPs
42
60
@@ -114,6 +132,8 @@ Manual configuration involves reviewing the following files so that they match y
114
132
* Configure the preferred listen port and [enable SSL/TLS configuration](https://docs.nginx.com/nginx/admin-guide/security-controls/terminating-ssl-http/)
115
133
* Modify the severity level of the `error_log` directive to suit the deployment environment
116
134
* Comment/uncomment the `auth_jwt_key_file` or `auth_jwt_key_request` directives based on whether `$oidc_jwt_keyfile` is a file or URI, respectively
135
+
* Uncomment the `proxy_set_header Authorization "Bearer $access_token"` directive if you want to pass access/bearer token in HTTP header to the protected backend/upstream
136
+
* Uncoment the `proxy_intercept_errors on` directive if the access token lifetime is less than the ID token lifetime
117
137
118
138
***openid_connect.server_conf** - this is the NGINX configuration for handling the various stages of OpenID Connect authorization code flow
119
139
* No changes are usually required here
@@ -128,8 +148,9 @@ Manual configuration involves reviewing the following files so that they match y
128
148
The key-value store is used to maintain persistent storage for ID tokens and refresh tokens. The default configuration should be reviewed so that it suits the environment. This is part of the advanced configuration in **openid_connect_configuration.conf**.
Users may receive the response with HTTP 401 "invalid token" despite of successful authentication. There are several reasons why an OIDC access token might be not accepted by upstream although if it is not expired as follows:
251
+
* Incorrect backend server configuration. NGINX Plus sends bearer token in the HTTP Authorization header, but the backend application expects it in a specific cookie.
252
+
* The token has been tampered with. OIDC access tokens are digitally signed by the authorization server to ensure their authenticity. If the token has been modified in any way, the signature will no longer be valid, and the token will be considered invalid.
253
+
* It is important to note that the scope of an OIDC access token is independent of its validity. Even if an OIDC access token is not expired and has not been revoked, it may still be considered invalid if it does not have the necessary scope for the requested action. Please check "$oidc_scopes" variable in the "openid_connect_configuration.conf" file.
254
+
226
255
## Support
227
256
228
257
This reference implementation for OpenID Connect is supported for NGINX Plus subscribers.
@@ -236,3 +265,4 @@ This reference implementation for OpenID Connect is supported for NGINX Plus sub
236
265
***R19** Minor bug fixes
237
266
***R22** Separate configuration file, supports multiple IdPs. Configurable scopes and cookie flags. JavaScript is imported as an indepedent module with `js_import`. Container-friendly logging. Additional metrics for OIDC activity.
238
267
***R23** PKCE support. Added support for deployments behind another proxy or load balancer.
268
+
***R28** Access token support. Added support for access token to authorize NGINX to access protected backend.
0 commit comments