2011-06-20 125 views
4

我有一个使用用户名/密码SpringSecurity配置的可用Web应用程序。现在我想将它移植到一个简单的Facebook应用程序中。出于某种原因,我想通过使用返回的Facebook访问令牌来进行身份验证,并保留用户名 - 密码验证器。在FacebookApp中将Facebook身份验证集成到Spring Security中

在细节,我会检查认证的用户的Facebook访问令牌,通过返回:

https://graph.facebook.com/oauth/access_token?client_id=[my_api_key]&redirect_uri=[my_redirect_uri]&client_secret=[my_api_secret]&code=[code]

用户不需要提供任何的用户名/密码,因为他们已经登录与Facebook。但我想保留(用户名/密码)弹簧安全配置,以便用户可以登录我的原始网站。

SpringSecurity支持这种认证吗?如果答案是肯定的,我想知道如何做到这一点?我是否需要编写自定义身份验证提供程序来执行此操作?

UPDATE:最后,我们有定制的方式SpringSecurity认证,使其接受的access_token作为验证参数通过扩展UsernamePasswordAuthenticationFilter(声明为formLoginFilter

+0

@HaveAGuess:我已经更新了我的问题的答案。 –

回答

9

有一个从春天另一个项目:Spring Social这非常有用。

它支持多个社交网络。我成功地用它来验证Facebook。然后我写了一个小功能,Facebook的用户登录到我的春季安全方面:

protected void authenticate(UserDTO user){ 
    SecurityContextHolder.getContext().getAuthentication(); 
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword()); 
    token.setDetails(new WebAuthenticationDetails(getRequest())); 
    Authentication authentication = authenticationManager.authenticate(token); 
    SecurityContextHolder.getContext().setAuthentication(authentication); 
} 

UserDTO需要有一个用户名和(生成)的密码属性和需要保存在数据库中,以便您的user-service(从春季安全)可以检索它。

+0

Bart Vangeneugden它不工作...显示错误..我也包括春天的API ..是否有任何API也是要添加 – lulu

相关问题