简体   繁体   中英

How can I custom url to access_denied from SpringSocial Facebook?

In ProviderSignInController we have a method oauth2ErrorCallback. When the user cancel authorization in facebook this method redirect to:

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

I need customize this url, how can do it?

I need redirect to my page, customized.

For now, I overrride the ProvidersignInCrontroller, but my feeling say to me that this is not the definitive 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);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM