I’m looking for some samples or articles that explain how to integrate spring social to my micro-services architecture, more specifically to my authorization server. Can sommeone explain how can i add spring social (Facebook and google) to the flow?
As i mentioned before, i’m using angular as a front-end application, right now i’m handling password flow, the user enter his username and password and get a JWT token, this token is used in each resource server calls. This is my security config and authorization config :
@EnableAuthorizationServer
@Configuration
public class ServersConfig extends AuthorizationServerConfigurerAdapter {
@Value("${security.oauth2.client-id}")
private String clientId;
@Value("${security.oauth2.signing-key}")
private String signingKey;
@Value("${security.oauth2.grant-type.password}")
private String grantTypePassword;
@Value("${security.oauth2.grant-type.authorization-code}")
private String grantTypeAuthorizationCode;
@Value("${security.oauth2.grant-type.refresh-token}")
private String grantTypeRefreshToken;
@Value("${security.oauth2.scope.web}")
private String scopeWeb;
@Value("${security.oauth2.scope.mobile}")
private String scopeMobile;
@Value("${security.oauth2.resources-ids.buy-sell}")
private String resourcesIdBuySell;
@Value("${security.oauth2.resources-ids.gateway}")
private String resourcesIdGateway;
@Value("${security.oauth2.resources-ids.upload}")
private String resourcesIdUpload;
@Value("${security.oauth2.access-token-validity-seconds}")
private String accessTokenValiditySeconds;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(signingKey);
return converter;
}
@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(accessTokenConverter());
}
@Bean
public DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
defaultTokenServices.setSupportRefreshToken(true);
return defaultTokenServices;
}
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer.inMemory().withClient(clientId).secret(signingKey).autoApprove(true)
.authorizedGrantTypes(grantTypeAuthorizationCode, grantTypePassword, grantTypeRefreshToken)
.scopes(scopeWeb, scopeMobile).resourceIds(resourcesIdBuySell, resourcesIdGateway, resourcesIdUpload);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore()).accessTokenConverter(accessTokenConverter())
.authenticationManager(authenticationManager);
}
}
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public UserDetailsService userDetailsService() {
return new UserServiceImpl();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsServiceBean()).passwordEncoder(passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/oauth/token", "/oauth/authorize", "/oauth/confirm_access").permitAll()
.anyRequest().authenticated().and().csrf().disable().cors().and()
.userDetailsService(userDetailsService());
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(HttpMethod.OPTIONS);
}
}