1
votes

i'm trying to exchange a received authorization code wth a token in a web application but when I call GoogleAuthorizationCodeTokenRequest i get this error : "Invalid parameter value for redirect_uri: Invalid scheme:https://mapmydayunamur.appspot.com/getauthcodeservlet"

I've tried many redirect_uri and don't know why I get this error. The Uri is in my redirect Uri in developers console. Here's my code : in getauthcodeservlet.java :

String authcode = req.getParameter("code");
        String clientID = "CLIENTID_FROM_GOOGLEDEVELOPERSCONSOLE"
        String clientSecret = "CLIENTSECRET_FROM_GOOGLEDEVELOPERSCONSOLE";
        String redirectUri = "https://mapmydayunamur.appspot.com/getauthcodeservlet";

try {
                GoogleTokenResponse response =
                    new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),clientID, clientSecret, authcode,redirectUri).execute();
                resp.getWriter().println("Access token: " + response.getAccessToken());
              } catch (TokenResponseException e) {
                if (e.getDetails() != null) {
                    resp.getWriter().println("Error: " + e.getDetails().getError());
                  if (e.getDetails().getErrorDescription() != null) {
                      resp.getWriter().println(e.getDetails().getErrorDescription());
                  }
                  if (e.getDetails().getErrorUri() != null) {
                      resp.getWriter().println(e.getDetails().getErrorUri());
                  }
                } else {
                    resp.getWriter().println(e.getMessage());
                }
              }
    }

Thanks for helping me

2
space character in front of the https? " https...pinoyyid
Sorry it was an error when copy-paste my code into the forum. Now it's the good version, doesn't work neither.. Thanks for your answer anyway !Gerome Laffineur

2 Answers

1
votes

Problem solved by inruducing the redirect_uri via

.setRedirectUri(getRedirectUri(req))

and adding the method

  static String getRedirectUri(HttpServletRequest req) {
        GenericUrl requestUrl = new GenericUrl(req.getRequestURL().toString());
        requestUrl.setRawPath("/getauthcodeservlet");
        return requestUrl.build();
      }
0
votes

You cannot specify a subdirectory. Per Google's documentation when changing Client Credential settings in the developer's console:

Cannot contain a wildcard (http://*.example.com) or a path (http://example.com/subdir).

So you should change to https://mapmydayunamur.appspot.com