Skip to content

Commit 03e3727

Browse files
Resource Request Signing at the UserInfo Endpoint
- `UserInfoEndpoint` class - Add request parameters related to HTTP Message Signatures. - `pom.xml` - Update the version of authlete-java-common from 4.9 to 4.12. - Update the version of authlete-java-jaxrs from 2.79 to 2.80.
1 parent bd64353 commit 03e3727

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414

15-
<authlete.java.common.version>4.9</authlete.java.common.version>
16-
<authlete.java.jaxrs.version>2.79</authlete.java.jaxrs.version>
15+
<authlete.java.common.version>4.12</authlete.java.common.version>
16+
<authlete.java.jaxrs.version>2.80</authlete.java.jaxrs.version>
1717
<authlete.cbor.version>1.18</authlete.cbor.version>
1818
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
1919
<jersey.version>2.30.1</jersey.version>

src/main/java/com/authlete/jaxrs/server/api/UserInfoEndpoint.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -22,7 +22,6 @@
2222
import javax.ws.rs.HeaderParam;
2323
import javax.ws.rs.POST;
2424
import javax.ws.rs.Path;
25-
import javax.ws.rs.QueryParam;
2625
import javax.ws.rs.core.Context;
2726
import javax.ws.rs.core.HttpHeaders;
2827
import 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

Comments
 (0)