0

I am trying to implement OAuth2 in my JAX-RS application, using Apache Oltu. I have found this: 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();
}

This works fine with application/x-www-form-urlencoded. However I want to have support for application/json too. I can't find any documentation how I extend or implement this. Is anyone familiar with this problem?

Preferably I want to reuse OAuthTokenRequest

Albert Bos
  • 2,012
  • 1
  • 15
  • 26

1 Answers1

0

The @Consumes and @Produces annotations from the JAX-RS api have support for an Array of Strings by default. You can declare your REST endpoint like this to support multiple formats: @Consumes({"application/x-www-form-urlencoded", "application/json"})

Fana Sithole
  • 340
  • 3
  • 10
  • Yes I am aware of that. But it seems that the Apache Oltu package doesn't give me support to do so with JSON. – Albert Bos Dec 11 '15 at 21:34
  • Hi @adhesivee, maybe I don't follow quite well when you say the Oltu package does not support JSON. What exactly are you trying to do? Are you trying to issue an access token request or are you trying to receive and process an access token request? – Fana Sithole Dec 14 '15 at 12:35
  • `OAuthTokenRequest` only accepts `HttpServletRequest` and it will only process `application/x-www-form-urlencoded` kind of messages. I want also to handle `application/json` kind of messages. I don't mind making a custom implementation, but by preference re-use as much as possible from the Oltu package. – Albert Bos Dec 17 '15 at 14:36