设置春季安全性通过Facebook登录后记住我的cookie [英] Set spring security remember me cookie after login via facebook
问题描述
我正在构建一个移动Web应用程序,该应用程序可以选择通过facebook/twitter登录.我希望应用程序通过Spring security的记住我"功能来记住登录,以便用户需要经常登录.
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.
我有一些部分可以调出Facebook,并获得可以识别用户的access_token.我可以使用
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);
虽然这将登录用户,但不会设置记住我" cookie.我在这里想念什么?
While this logs in the user, it does not set the remember me cookie. What am I missing here?
谢谢!
推荐答案
尝试注入RememberMeServices
接口的实现,然后尝试做:
Try to inject the implementation of RememberMeServices
interface and then try to do:
rememberMeServices.loginSuccess(request, response, auth);
确保请求中存在_spring_security_remember_me
参数.
这篇关于设置春季安全性通过Facebook登录后记住我的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!