我正在尝试使用Apache Oltu在我的JAX-RS应用程序中实现OAuth2。我发现了这个: https://github.com/apache/oltu/tree/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException
{
OAuthTokenRequest oauthRequest = null;
OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
try {
oauthRequest = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e)
.buildJSONMessage();
return Response.status(res.getResponseStatus()).entity(res.getBody()).build();
}
这适用于application/x-www-form-urlencoded
。但是,我也希望得到application/json
的支持。我找不到任何文档如何扩展或实现它。有人熟悉这个问题吗?
我希望重用OAuthTokenRequest
答案 0 :(得分:0)
默认情况下,来自JAX-RS api的@Consumes
和@Produces
注释支持字符串数组。您可以像这样声明REST端点以支持多种格式:@Consumes({"application/x-www-form-urlencoded", "application/json"})