Set spring security remember me cookie after login via facebook

无人久伴 提交于 2020-01-11 07:08:28

问题


I am building a mobile web app that has the option to login via facebook/twitter. I want the app to remember the login via Spring security's remember me functionality so that the user need to have to login frequently.

I have the parts that will call out to facebook and get the access_token that will identify the user. I can login the user using

    SecurityContextHolder.getContext().setAuthentication(
        new UsernamePasswordAuthenticationToken(principal, credentials, authorities));

I am trying to use similar approach to add remember me functionality by

    RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken(key, principal, authorities);
    SecurityContextHolder.getContext().setAuthentication(auth);

While this logs in the user, it does not set the remember me cookie. What am I missing here?

Thanks!


回答1:


Try to inject the implementation of RememberMeServices interface and then try to do:

rememberMeServices.loginSuccess(request, response, auth);

Be sure that _spring_security_remember_me parameter is present in the request.



来源:https://stackoverflow.com/questions/16041685/set-spring-security-remember-me-cookie-after-login-via-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!