Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9690c3

Browse files
committedJan 9, 2023
Add OIDC userinfo endpoint
remove /userinfo location Add userinfo endpoint in README.md
1 parent 74948ce commit c9690c3

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed
 

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ For more information on OpenID Connect and JWT validation with NGINX Plus, see [
4040

4141
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.
4242

43+
### Userinfo Endpoint
44+
45+
The [Userinfo Endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo) is an OAuth 2.0 protected resource that returns claims about the authenticated End-User. For User Agent To obtain the requested claims about the End-User, NGINX Plus makes a request to the `$oidc_userinfo_endpoint` using an access token as the example of `/foobar` location in the config file of `frontend.conf`. These claims are normally represented by a JSON object that contains a collection of name and value pairs for the claims.
46+
4347
### Logout
4448

4549
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.
@@ -102,6 +106,7 @@ When NGINX Plus is deployed behind another proxy, the original protocol and port
102106
* Obtain the URL for `jwks_uri` or download the JWK file to your NGINX Plus instance
103107
* Obtain the URL for the **authorization endpoint**
104108
* Obtain the URL for the **token endpoint**
109+
* Obtain the URL for the **userinfo endpoint**
105110

106111
## Configuring NGINX Plus
107112

‎configure.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fi
120120
# Build an intermediate configuration file
121121
# File format is: <NGINX variable name><space><IdP value>
122122
#
123-
jq -r '. | "$oidc_authz_endpoint \(.authorization_endpoint)\n$oidc_token_endpoint \(.token_endpoint)\n$oidc_jwks_uri \(.jwks_uri)"' < /tmp/${COMMAND}_$$_json > /tmp/${COMMAND}_$$_conf
123+
jq -r '. | "$oidc_authz_endpoint \(.authorization_endpoint)\n$oidc_token_endpoint \(.token_endpoint)\n$oidc_jwks_uri \(.jwks_uri)\n$oidc_userinfo_endpoint \(.userinfo_endpoint)"' < /tmp/${COMMAND}_$$_json > /tmp/${COMMAND}_$$_conf
124124

125125
# Create a random value for HMAC key, adding to the intermediate configuration file
126126
echo "\$oidc_hmac_key `openssl rand -base64 18`" >> /tmp/${COMMAND}_$$_conf
@@ -178,7 +178,7 @@ fi
178178

179179
# Loop through each configuration variable
180180
echo "$COMMAND: NOTICE: Configuring $CONFDIR/openid_connect_configuration.conf"
181-
for OIDC_VAR in \$oidc_authz_endpoint \$oidc_token_endpoint \$oidc_jwt_keyfile \$oidc_hmac_key $CLIENT_ID_VAR $CLIENT_SECRET_VAR $PKCE_ENABLE_VAR; do
181+
for OIDC_VAR in \$oidc_authz_endpoint \$oidc_token_endpoint \$oidc_jwt_keyfile \$oidc_userinfo_endpoint \$oidc_hmac_key $CLIENT_ID_VAR $CLIENT_SECRET_VAR $PKCE_ENABLE_VAR; do
182182
# Pull the configuration value from the intermediate file
183183
VALUE=`grep "^$OIDC_VAR " /tmp/${COMMAND}_$$_conf | cut -f2 -d' '`
184184
echo -n "$COMMAND: NOTICE: - $OIDC_VAR ..."

‎frontend.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ server {
4040

4141
access_log /var/log/nginx/access.log main_jwt;
4242
}
43+
44+
location = /foobar {
45+
# This location is an example for User Agent to obtain requested claims
46+
# about the End-User if necessary:
47+
# - https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
48+
error_page 401 = @do_oidc_flow;
49+
proxy_intercept_errors on;
50+
proxy_ssl_server_name on;
51+
proxy_set_header Authorization "Bearer $access_token";
52+
proxy_pass $oidc_userinfo_endpoint;
53+
}
4354
}
4455

4556
# vim: syntax=nginx

‎openid_connect_configuration.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ map $host $oidc_jwt_keyfile {
2828
default "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/certs";
2929
}
3030

31+
map $host $oidc_userinfo_endpoint {
32+
default "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/userinfo";
33+
}
34+
3135
map $host $oidc_client {
3236
default "my-client-id";
3337
}

0 commit comments

Comments
 (0)
Please sign in to comment.