我需要在提供商中同时使用Facebook和Google作为OpenId Sing。我使用SocialAuthenticationFilter将它们与Spring Security集成在一起,如documentation中所述,并查看示例应用程序。
我已经成功配置了Facebook。
问题在于我尝试向Google进行身份验证时:
在<option ng-repeat="value in crtController.quantity.values track by
value | filterQuantity " value="{{value}}" ng-bind="value"></option>
filters.filter('filterQuantity', function () {
return function(tasks, tags) {
return tasks.filter(function(value) {
...
});
};
});
OAuth2AuthenticationService.getAuthToken():
此时我可以看到accessGrant包含一个accessToken,所以到目前为止似乎是正确的。它在以下调用中失败:
...
AccessGrant accessGrant = getConnectionFactory().getOAuthOperations().exchangeForAccess(code, returnToUrl, null);
// TODO avoid API call if possible (auth using token would be fine)
Connection<S> connection = getConnectionFactory().createConnection(accessGrant);
最终致电createConnection()
:
GoogleConnectionFactory.extractProviderUserId(AccessGrant accessGrant)
和Google api = ((GoogleServiceProvider)getServiceProvider()).getApi(accessGrant.getAccessToken());
UserProfile userProfile = getApiAdapter().fetchUserProfile(api);
...
- &gt; getApiAdapter().fetchUserProfile(Google)
抛出403异常:
google.plusOperations().getGoogleProfile();
为什么不能获得GoogleProfile?显然我设置的范围和提示给用户的内容是正确的......
完整项目可在此处获取:https://github.com/codependent/spring-boot-social-signin
摘自配置:
SecurityConfig :
org.springframework.web.client.HttpClientErrorException: 403 Forbidden
SocialConfig :
@EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secure*").authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
//.loginProcessingUrl("/secure-home")
.failureUrl("/login?param.error=bad_credentials")
.and()
.logout()
.logoutUrl("/logout")
.deleteCookies("JSESSIONID")
.and()
/*.rememberMe()
.and()*/
.apply(new SpringSocialConfigurer());
}
@Bean
public SocialUserDetailsService socialUserDetailsService(){
return new SocialUserDetailsService(){
@Override
public SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException{
return new SimpleSocialUserDetails(userId);
}
}
}
}
答案 0 :(得分:2)
已修复,我必须在Google Developer Console上启用Google+ API。