-3

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);
    }
}
Free23
  • 15
  • 5
  • Hello Free23 - Stackoverflow is designed as a Question and Answer site for more specific questions, this is far too broad of a question for someone to answer on this site. I'd suggest you ask more specific questions in the future and also give samples of your code/ markup/ etc to support that and describe the steps you've already taken. – Daniel Turcich Oct 30 '18 at 17:21
  • Hi Daniel, 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. 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 : – Free23 Oct 31 '18 at 02:38

1 Answers1

0

Depends on what OAuthServer you're using. Personally i'm using a ASP.NET Core back end with IdentityServer and it has support for external logins https://identityserver4.readthedocs.io/en/release/quickstarts/4_external_authentication.html

I've also tried this on nodeJS using passportJS http://www.passportjs.org/docs/

Both of these OAuthServers have support for facebook and google, you just have to wire up your claims based on the data you received from either facebook or google.

dardardardar
  • 314
  • 1
  • 12