如何从SpringSocial Facebook自定义URL到access_denied?

时间:2018-03-23 20:17:09

标签: spring-security spring-social-facebook

ProviderSignInController中,我们有一个方法oauth2ErrorCallback。 当用户在facebook中取消授权时,此方法会重定向到:

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

我需要自定义此网址,怎么做?

我需要重定向到我的页面,自定义。

1 个答案:

答案 0 :(得分:0)

现在,我重写了ProvidersignInCrontroller,但我的感觉告诉我,这不是最终的解决方案

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);
    }

}