11/*
2- * Copyright (C) 2016-2022 Authlete, Inc.
2+ * Copyright (C) 2016-2024 Authlete, Inc.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222import javax .ws .rs .HeaderParam ;
2323import javax .ws .rs .POST ;
2424import javax .ws .rs .Path ;
25- import javax .ws .rs .QueryParam ;
2625import javax .ws .rs .core .Context ;
2726import javax .ws .rs .core .HttpHeaders ;
2827import javax .ws .rs .core .MediaType ;
@@ -61,7 +60,7 @@ public Response get(
6160 String accessToken = extractAccessToken (authorization , null );
6261
6362 // Handle the userinfo request.
64- return handle (request , accessToken , dpop );
63+ return handle (request , /*body*/ null , accessToken , dpop );
6564 }
6665
6766
@@ -98,7 +97,7 @@ public Response post(
9897 accessToken = extractAccessToken (authorization , accessToken );
9998
10099 // Handle the userinfo request.
101- return handle (request , accessToken , dpop );
100+ return handle (request , body , accessToken , dpop );
102101 }
103102
104103
@@ -119,17 +118,20 @@ private static String extractFormParameter(HttpServletRequest request, String bo
119118 /**
120119 * Handle the userinfo request.
121120 */
122- private Response handle (HttpServletRequest request , String accessToken , String dpop )
121+ private Response handle (
122+ HttpServletRequest request , String body ,
123+ String accessToken , String dpop )
123124 {
124- Params params = buildParams (request , accessToken , dpop );
125+ Params params = buildParams (request , body , accessToken , dpop );
125126
126127 return handle (AuthleteApiFactory .getDefaultApi (),
127128 new UserInfoRequestHandlerSpiImpl (), params );
128129 }
129130
130131
131132 private Params buildParams (
132- HttpServletRequest request , String accessToken , String dpop )
133+ HttpServletRequest request , String body ,
134+ String accessToken , String dpop )
133135 {
134136 Params params = new Params ();
135137
@@ -156,6 +158,29 @@ private Params buildParams(
156158 // setHtu(String) method here intentionally. Note that this means you
157159 // have to set "userInfoEndpoint" properly to support DPoP.
158160
161+ // HTTP Message Signatures
162+ params .setHeaders (extractHeadersAsPairs (request ))
163+ .setRequestBodyContained (body != null )
164+ //.setTargetUri(targetUri)
165+ ;
166+
167+ // We can reconstruct the target URI using request.getRequestURL() and
168+ // request.getQueryString() and set it to params by the setTargetUri(URI)
169+ // method. However, behind proxies, the constructed URI may be different
170+ // from the original one.
171+ //
172+ // If the "targetUri" parameter is omitted, the value of the "htu"
173+ // parameter is used. The "htu" parameter represents the URL of the
174+ // userinfo endpoint, which usually serves as the target URI of the
175+ // userinfo request. The only exception is when the access token is
176+ // specified as a query parameter, as defined in RFC 6750 Section 2.3.
177+ // However, RFC 6750 states that this method "SHOULD NOT be used"
178+ // unless other methods are not viable.
179+ //
180+ // If neither the "targetUri" parameter nor the "htu" parameter is
181+ // specified, the "userInfoEndpoint" property of the service is used
182+ // as a fallback.
183+
159184 return params ;
160185 }
161186}
0 commit comments