【问题标题】:Spring Social and AngularSpring 社交和 Angular
【发布时间】:2019-04-03 19:12:10
【问题描述】:

我正在寻找一些示例或文章来解释如何将 spring social 集成到我的微服务架构中,更具体地说是集成到我的授权服务器中。有人可以解释我如何将春季社交(Facebook 和谷歌)添加到流程中吗?

正如我之前提到的,我使用 Angular 作为前端应用程序,现在我正在处理密码流,用户输入他的用户名和密码并获得一个 JWT 令牌,这个令牌用于每个资源服务器来电。这是我的安全配置和授权配置:

@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 - Stackoverflow 被设计为一个问答网站,用于更具体的问题,这个问题太宽泛了,无法在这个网站上回答。我建议您以后提出更具体的问题,并提供您的代码/标记/等示例以支持这一点并描述您已经采取的步骤。
  • 嗨,Daniel,我正在寻找一些示例或文章来解释如何将 Spring Social 集成到我的微服务架构中,更具体地说,是集成到我的授权服务器中。正如我之前提到的,我使用 Angular 作为前端应用程序,现在我正在处理密码流,用户输入他的用户名和密码并获得一个 JWT 令牌,这个令牌用于每个资源服务器调用。这是我的安全配置和授权配置:

标签: angular spring-boot spring-social


【解决方案1】:

取决于您使用的 OAuthServer。就我个人而言,我正在使用带有 IdentityServer 的 ASP.NET Core 后端,它支持外部登录 https://identityserver4.readthedocs.io/en/release/quickstarts/4_external_authentication.html

我也在 nodeJS 上使用 passportJS http://www.passportjs.org/docs/ 尝试过这个

这两个 OAuthServer 都支持 facebook 和 google,您只需根据从 facebook 或 google 收到的数据来连接您的声明。

【讨论】:

    猜你喜欢
    • 2020-03-09
    • 1970-01-01
    • 2019-05-19
    • 2020-07-02
    • 2016-09-22
    • 2015-08-28
    • 2012-01-22
    • 1970-01-01
    • 2019-03-03
    相关资源
    最近更新 更多