How to customize the denied access url? (spring social facebook)

0

In class ProviderSignInController We have the oauth2ErrorCallback method. When the user cancels authorization in facebook it is redirected to:

/signin?error=access_denied&error_description=Permissions+error

I need to customize this url , how can I do this?

I need to redirect to a custom page of mine.

    
asked by anonymous 23.03.2018 / 21:21

1 answer

0

For now I'm overwriting the ProviderSignInController class, but my foreboding tells me that this is not the best solution

class MyProviderSignInController extends ProviderSignInController {
    private final Logger log = LoggerFactory.getLogger(MyProviderSignInController.class);

    private String urlToOauth2ErrorCallback;

    public MyProviderSignInController(ConnectionFactoryLocator connectionFactoryLocator,
            UsersConnectionRepository usersConnectionRepository, SignInAdapter signInAdapter) {
        super(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
    }

    public void defineUrlToOauth2ErrorCallback(String urlToOauth2ErrorCallback) {
        this.urlToOauth2ErrorCallback = urlToOauth2ErrorCallback;
    }

    @RequestMapping(value = "/{providerId}", method = RequestMethod.GET, params = "error")
    public RedirectView oauth2ErrorCallback(@PathVariable String providerId, @RequestParam("error") String error,
            @RequestParam(value = "error_description", required = false) String errorDescription,
            @RequestParam(value = "error_uri", required = false) String errorUri, NativeWebRequest request) {
        log.warn("Error during authorization: " + error);

        if (urlToOauth2ErrorCallback != null) {
            return new RedirectView(urlToOauth2ErrorCallback, false);
        }

        return super.oauth2ErrorCallback(providerId, error, errorDescription, errorUri, request);
    }

}
    
23.03.2018 / 22:19