我在使用Spring Social中的Facebook API尝试实现注销按钮时遇到了麻烦。
要注销,我是否必须像在下面的登录按钮中那样调用URL?
我能够实现登录网址' / connect / facebook '如下:
<form action="/connect/facebook" method="POST">
<input type="hidden" name="scope" value="read_stream,email" />
<md-button type="submit">
<i class="fa fa-facebook-square"></i> Login
</md-button>
</form>
我还扩展了ConnectController以将用户重定向到主页:
@Controller
public class FacebookController extends ConnectController {
@Inject
public FacebookController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
@Override
protected String connectedView(String providerId){
return "redirect:/";
}
}
我正在使用AngularJS来获取用户,如果已连接,下面是我负责的服务:
function login() {
var request = $http({
method: "GET",
url: "/home/user"
});
return (request.then(handleSuccess, handleError));
}
后端的其余控制器用于查找或注册用户:
@RestController
public class LoginController {
@Autowired
private Facebook facebook;
@Autowired
private UsrService usrService;
@RequestMapping(value = "/home/user", method = RequestMethod.GET)
public Usr findUser() {
Usr user;
if (!facebook.isAuthorized()) {
return null;
}
String name = facebook.userOperations().getUserProfile().getName();
String email = facebook.userOperations().getUserProfile().getEmail();
byte[] avatar = facebook.userOperations().getUserProfileImage(ImageType.SQUARE);
user = usrService.find(email);
// saves the new user
if (user == null) {
user = new Usr(email, name, avatar, 0);
user.setName(name);
user.setAvatar(avatar);
user.setLikes(0);
usrService.save(user);
}
return user;
}
}
我找不到任何接近我实现登录方式的解决方案,我也检查了github上的spring-social示例,但是它们的实现与我的实现完全不同。
感谢。
答案 0 :(得分:3)