0

The spring boot do not recognize my controllers only if i send more parameters on request. For example:

If i send normal GET request the spring boot recognize my controller: http://localhost/idp/oauth/123/authorize

If i send GET request with extras parameters the spring boot do not recognize my controller: http://localhost/idp/oauth/123/authorize?scope=public_profile

I need receive the request exactly for second example (with parameter scope), but the spring boot do not recognize the controller and redirect to /error.

code:

@Controller
@RequestMapping("/idp/oauth")
public class OAuthController {

    @RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.GET)
    public String authorizeGet(
            HttpServletRequest request, 
            HttpServletResponse response, 
            @PathVariable String clientId,
            Model model) {
            // ...
    }

    @RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.POST)
    public String authorizePost(
            HttpServletRequest request, 
            HttpServletResponse response, 
            @PathVariable String clientId,
            Model model) {
            // ...
    }
}
1
  • Have you tried adding @RequestParams? Commented Oct 5, 2019 at 14:39

2 Answers 2

2

Since you are passing extra param with name "scope" Spring will search for @RequestParam in methods It can't find any, thus the error

You need to modify your method to add all @RequestParam

You can also add optional fields if they are not mandatory with required = false

@RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.GET)
public String authorizeGet(
        HttpServletRequest request, 
        HttpServletResponse response, 
        @PathVariable String clientId,
        @RequestParam(value = "scope") String scope,
        @RequestParam(required = false, value = "optionalParam") String optionalParam,
        Model model) {
        // ...
}
Sign up to request clarification or add additional context in comments.

4 Comments

Adding the '@RequestParam(name = "scope") String scope' dont work :(. the redirect /error continue.
Can you add Serevr log what errror exactly you are getting.
Instead of name try "value = "scope" . I have edited
I try using "value = scope" but dont works :( The spring redirect me to /error. (the recognize url, but if i send parameters do not recognize more)...
1

You missed @RequestParam in the controller method definition.

More on @RequestParam

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.