Skip to content

Commit fedccf9

Browse files
committed
Add OIDC userinfo endpoint
1 parent 74948ce commit fedccf9

5 files changed

+38
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ When NGINX Plus is deployed behind another proxy, the original protocol and port
102102
* Obtain the URL for `jwks_uri` or download the JWK file to your NGINX Plus instance
103103
* Obtain the URL for the **authorization endpoint**
104104
* Obtain the URL for the **token endpoint**
105+
* Obtain the URL for the **userinfo endpoint**
105106

106107
## Configuring NGINX Plus
107108

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.server_conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@
6666
error_page 500 502 504 @oidc_error;
6767
}
6868

69+
location = /userinfo {
70+
# This location is to provide signed-in user information claims that are
71+
# defined in $oidc_userinfo_required_claims.
72+
default_type application/json;
73+
if ($oidc_userinfo_required_claims = '') {
74+
return 200 '{"name": "", "message":"details not provided per your policy"}';
75+
}
76+
js_content oidc.userInfo;
77+
}
78+
79+
location = /_userinfo {
80+
# This location is called by oidc.userInfo() when calling /userinfo
81+
# to get signed-in user information from the OP:
82+
# - https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
83+
internal;
84+
proxy_ssl_server_name on; # For SNI to the IdP
85+
proxy_set_header Authorization "Bearer $access_token";
86+
proxy_pass $oidc_userinfo_endpoint;
87+
}
88+
6989
location = /logout {
7090
status_zone "OIDC logout";
7191
add_header Set-Cookie "auth_token=; $oidc_cookie_flags"; # Send empty cookie

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)