我'm writing an App Gateway (REST-API) and a Web Application using Spring Boot. I'有一个包含用户和密码哈希的用户数据库 . 两个应用程序都将使用相同的用户数据库,因此我希望将它放在一个独立的服务中 . 我已经查看https://spring.io/guides/tutorials/spring-security-and-angular-js/,提出了通过OAuth使用Auth服务器的想法 .

我对用例的请求流程非常不确定 . 我认为它将进入App - > App Gateway(例如Login),然后使用授权类型密码向/ uaa / oauth / token发出请求(因为我获得了用户凭据) . 此请求必须包含client_id和client_secret,并应返回令牌 .

  • 这个概念对我的用例来说是否正确?

  • 如果是这样:我如何配置Auth服务器以使用数据库而不是基本身份验证?我发现的所有示例在application.properties中都有一定的用户/ pw组合

  • 通过用户名pw将Auth委派给Auth服务器的最惯用方法是什么?

编辑:我发现这非常有用:https://github.com/dsyer/sparklr-boot

现在我能做到:

curl -H "Accept: application/json" my-trusted-client@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=password

如何将一些用户后端连接到它?据我所知,以下使用默认的Spring Basic Auth设置 .

application.yml:

security:
  user:
    password: password

码:

@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints)
            throws Exception {
        endpoints.authenticationManager(authenticationManager);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        // @formatter:off
        clients.inMemory().withClient("my-trusted-client")
                .authorizedGrantTypes("password", "authorization_code",
                        "refresh_token", "implicit")
                .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
                .scopes("read", "write", "trust").resourceIds("sparklr")
                .accessTokenValiditySeconds(60).and()
                .withClient("my-client-with-registered-redirect")
                .authorizedGrantTypes("authorization_code").authorities("ROLE_CLIENT")
                .scopes("read", "trust").resourceIds("sparklr")
                .redirectUris("http://anywhere?key=value").and()
                .withClient("my-client-with-secret")
                .authorizedGrantTypes("client_credentials", "password")
                .authorities("ROLE_CLIENT").scopes("read").resourceIds("sparklr")
                .secret("secret");
        // @formatter:on
    }

}