oltu-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Ukpong (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (OLTU-26) Guice+Jersey+Amber: Can't correctly create OAuthTokenRequest instance
Date Wed, 21 Oct 2015 16:19:27 GMT

    [ https://issues.apache.org/jira/browse/OLTU-26?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14967383#comment-14967383
] 

Michael Ukpong edited comment on OLTU-26 at 10/21/15 4:18 PM:
--------------------------------------------------------------

Hi Antonio and Aleksandar. I have been battling this same issue for days. I am using Oltu
1.0.1, deploying on Jetty using org.glassfish.jersey.servlet.ServletContainer. Same error:{"error_description":"Missing
grant_type parameter value","error":"invalid_request"}

I have written a Request wrapper like this: 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.ws.rs.core.MultivaluedMap;

public class OAuthRequestWrapper extends HttpServletRequestWrapper {

    private MultivaluedMap<String, String> form;

    public OAuthRequestWrapper(HttpServletRequest request, MultivaluedMap<String, String>
form)
    { super(request); this.form = form; }

    @Override
    public String getParameter(String name) {
        String value = super.getParameter(name);
        if (value == null)
        { value = form.getFirst(name); }
        return value;
    }
    
    @Override
    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);
        if(values == null && form.get(name) != null){
            values = new String[form.get(name).size()];
            values = form.get(name).toArray(values);
        }
        return values;
    }
}

Still getting the same error. what did you say was the walkaround?

Thanks



was (Author: michaelukpong):
Hi Antonio and Aleksandar. I have been battling this same issue for days. I am using Otus
1.0.1, deploying on Jetty using org.glassfish.jersey.servlet.ServletContainer. Same error:{"error_description":"Missing
grant_type parameter value","error":"invalid_request"}

I have written a Request wrapper like this: 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.ws.rs.core.MultivaluedMap;

public class OAuthRequestWrapper extends HttpServletRequestWrapper {

    private MultivaluedMap<String, String> form;

    public OAuthRequestWrapper(HttpServletRequest request, MultivaluedMap<String, String>
form)
    { super(request); this.form = form; }

    @Override
    public String getParameter(String name) {
        String value = super.getParameter(name);
        if (value == null)
        { value = form.getFirst(name); }
        return value;
    }
    
    @Override
    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);
        if(values == null && form.get(name) != null){
            values = new String[form.get(name).size()];
            values = form.get(name).toArray(values);
        }
        return values;
    }
}

Still getting the same error. what did you say was the walkaround?

Thanks


> Guice+Jersey+Amber: Can't correctly create OAuthTokenRequest instance
> ---------------------------------------------------------------------
>
>                 Key: OLTU-26
>                 URL: https://issues.apache.org/jira/browse/OLTU-26
>             Project: Apache Oltu
>          Issue Type: Bug
>          Components: oauth2-common
>         Environment: jersey 1.10
> guice 3.0-SNAPSHOT
> amber 0.22-incubating-SNAPSHOT
>            Reporter: Alexander Urmuzov
>
> I've got a problem with creating OAuthTokenRequest.
> It needs an instance of HttpServletRequest on creation, but all instances which I can
get through guice or jersey injections have no post parameters.
> Guice injection example:
>     private final Provider<HttpServletRequest> requestProvider;
>     @Inject
>     public TokenEndpoint(Provider<HttpServletRequest> requestProvider) {
>         this.requestProvider = requestProvider;
>     }
>     @POST
>     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>     @Produces(MediaType.APPLICATION_JSON)
>     public Response authorize() throws OAuthSystemException {
>         OAuthTokenRequest oauthRequest = null;
>         try {
>             oauthRequest = new OAuthTokenRequest(requestProvider.get());
>     ....
> Jersey injection example:
>     @POST
>     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>     @Produces(MediaType.APPLICATION_JSON)
>     public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException
{
>         OAuthTokenRequest oauthRequest = null;
>         try {
>             oauthRequest = new OAuthTokenRequest(request);
> Looks like jersey have parsed HttpServletRequest and removed all post parameters from
it.
> If I attach filter that tries to get some parameter from HttpServletRequest before jersey,
my code works, but with exception from jersey.
> But I can retrieve MultivaluedMap of post parameters from jersey with all data and no
errors.
> I think there must be some alternative constructor for such environments. Any thoughts?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message