Skip to content

Commit 764d11b

Browse files
Recognize the "DPoP" HTTP header at the PAR endpoint
1 parent 7623165 commit 764d11b

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
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>3.86</authlete.java.common.version>
16-
<authlete.java.jaxrs.version>2.66</authlete.java.jaxrs.version>
15+
<authlete.java.common.version>3.88</authlete.java.common.version>
16+
<authlete.java.jaxrs.version>2.70</authlete.java.jaxrs.version>
1717
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
1818
<jersey.version>2.30.1</jersey.version>
1919
<jetty.version>9.4.27.v20200227</jetty.version>

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

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33

44
import javax.servlet.http.HttpServletRequest;
55
import javax.ws.rs.Consumes;
6-
import javax.ws.rs.HeaderParam;
76
import javax.ws.rs.POST;
87
import javax.ws.rs.Path;
98
import javax.ws.rs.core.Context;
109
import javax.ws.rs.core.HttpHeaders;
1110
import javax.ws.rs.core.MediaType;
1211
import javax.ws.rs.core.MultivaluedMap;
1312
import javax.ws.rs.core.Response;
13+
import com.authlete.common.api.AuthleteApi;
1414
import com.authlete.common.api.AuthleteApiFactory;
1515
import com.authlete.jaxrs.BasePushedAuthReqEndpoint;
16+
import com.authlete.jaxrs.PushedAuthReqHandler.Params;
1617

1718

1819
/**
1920
* An implementation of a pushed authorization endpoint.
20-
*
21+
*
2122
* @see <a href="https://tools.ietf.org/html/draft-lodderstedt-oauth-par"
2223
* >OAuth 2.0 Pushed Authorization Requests</a>
23-
*
24+
*
2425
* @author Justin Richer
2526
*
2627
*/
@@ -35,13 +36,56 @@ public class PushedAuthReqEndpoint extends BasePushedAuthReqEndpoint
3536
@POST
3637
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
3738
public Response post(
38-
@HeaderParam(HttpHeaders.AUTHORIZATION) String authorization,
39-
MultivaluedMap<String, String> parameters,
40-
@Context HttpServletRequest request)
39+
@Context HttpServletRequest request,
40+
MultivaluedMap<String, String> parameters)
4141
{
42-
String[] clientCertificates = extractClientCertificateChain(request);
42+
// Authlete API
43+
AuthleteApi authleteApi = AuthleteApiFactory.getDefaultApi();
44+
45+
// Parameters for Authlete's pushed_auth_req API.
46+
Params params = buildParams(request, parameters);
47+
48+
// Handle the PAR request.
49+
return handle(authleteApi, params);
50+
}
51+
52+
53+
private Params buildParams(
54+
HttpServletRequest request, MultivaluedMap<String, String> parameters)
55+
{
56+
Params params = new Params();
57+
58+
// RFC 6749
59+
// The OAuth 2.0 Authorization Framework
60+
params.setParameters(parameters)
61+
.setAuthorization(request.getHeader(HttpHeaders.AUTHORIZATION))
62+
;
63+
64+
// MTLS
65+
// RFC 8705 : OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound Access Tokens
66+
params.setClientCertificatePath(extractClientCertificateChain(request));
67+
68+
// DPoP
69+
// RFC 9449 : OAuth 2.0 Demonstrating Proof of Possession (DPoP)
70+
params.setDpop(request.getHeader("DPoP"))
71+
.setHtm("POST")
72+
//.setHtu(request.getRequestURL().toString())
73+
;
74+
75+
// We can reconstruct the URL of the PAR endpoint by calling
76+
// request.getRequestURL().toString() and set it to params by the
77+
// setHtu(String) method. However, the calculated URL may be invalid
78+
// behind proxies.
79+
//
80+
// If "htu" is not set here, the "pushedAuthReqEndpoint" property of
81+
// "Service" (which can be configured by using Authlete's web console)
82+
// is referred to as the default value. Therefore, we don't call the
83+
// setHtu(String) method here intentionally. Note that this means you
84+
// have to set "pushedAuthReqEndpoint" properly to support DPoP.
85+
86+
// Even the call of the setHtm(String) method can be omitted, too.
87+
// When "htm" is not set, "POST" is used as the default value.
4388

44-
return handle(AuthleteApiFactory.getDefaultApi(),
45-
parameters, authorization, clientCertificates);
89+
return params;
4690
}
4791
}

0 commit comments

Comments
 (0)