Oauth 2.0 Spring OAUTH2用于有角度的web应用程序

Oauth 2.0 Spring OAUTH2用于有角度的web应用程序,oauth-2.0,spring-security-oauth2,Oauth 2.0,Spring Security Oauth2,我正在尝试为web应用程序实现OAUTH2,需要一个简单的OAUTH2设置来保护RESTAPI。其中一个RESTAPI提供了登录功能,其中验证了用户凭证(用户名/密码)。我的用例如下: 1.API客户端目前是AngularJS,但将来可能会有其他客户端 2.使用用户名和密码登录应用程序的用户,即UI层(angular)调用登录rest服务,并在成功身份验证后生成具有到期时间的访问令牌。 3.客户端使用此生成的访问令牌来使用应用程序中的其他API 请为上述用例推荐一个简单的OAUTH2配置?Spr

我正在尝试为web应用程序实现OAUTH2,需要一个简单的OAUTH2设置来保护RESTAPI。其中一个RESTAPI提供了登录功能,其中验证了用户凭证(用户名/密码)。我的用例如下:
1.API客户端目前是AngularJS,但将来可能会有其他客户端
2.使用用户名和密码登录应用程序的用户,即UI层(angular)调用登录rest服务,并在成功身份验证后生成具有到期时间的访问令牌。
3.客户端使用此生成的访问令牌来使用应用程序中的其他API


请为上述用例推荐一个简单的OAUTH2配置?

Spring OAUTH2附带内置端点,以通过API获得访问令牌,该端点具有

下面是一个简单的配置

@Configuration
public class OAuth2ServerConfiguration {

    private static final String RESOURCE_ID = "tonywebapp-restservice";

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends
        AuthorizationServerConfigurerAdapter {

        @Autowired
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;

        @Autowired
        private UserApprovalHandler userApprovalHandler;

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {

            endpoints
                    .tokenStore(tokenStore())
                    .userApprovalHandler(userApprovalHandler)
                    .authenticationManager(authenticationManager)
                    .pathMapping("/oauth/error", "/oauth/error.html")
                    .pathMapping("/oauth/confirm_access", "/oauth/confirm_access.html")
                    ;

        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients
                .inMemory()
                    .withClient("your_client_id_here")
                        .resourceIds(RESOURCE_ID)
                        .authorizedGrantTypes("password", "refresh_token")
                        .authorities("USER")
                        .scopes("read.some.thing", "write.some.thing", "any.thing.you.want")
                        .resourceIds(RESOURCE_ID)
                        .secret("your_secret_here");
        }

        @Bean
        @Primary
        public DefaultTokenServices tokenServices() {
            DefaultTokenServices tokenServices = new DefaultTokenServices();
            tokenServices.setSupportRefreshToken(true);
            tokenServices.setTokenStore(tokenStore ());
            return tokenServices;
        }

        @Bean
        public TokenStore tokenStore() {
            return new InMemoryTokenStore();
        }

    }

}

但是,建议不要将这项拨款用于基于web的应用程序。因为你不能保护你的
秘密
。我正在为我的AngularJS web应用程序使用
implicit
grant类型。

Spring OAuth2附带内置端点,通过API获得访问令牌

下面是一个简单的配置

@Configuration
public class OAuth2ServerConfiguration {

    private static final String RESOURCE_ID = "tonywebapp-restservice";

    @Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends
        AuthorizationServerConfigurerAdapter {

        @Autowired
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;

        @Autowired
        private UserApprovalHandler userApprovalHandler;

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {

            endpoints
                    .tokenStore(tokenStore())
                    .userApprovalHandler(userApprovalHandler)
                    .authenticationManager(authenticationManager)
                    .pathMapping("/oauth/error", "/oauth/error.html")
                    .pathMapping("/oauth/confirm_access", "/oauth/confirm_access.html")
                    ;

        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients
                .inMemory()
                    .withClient("your_client_id_here")
                        .resourceIds(RESOURCE_ID)
                        .authorizedGrantTypes("password", "refresh_token")
                        .authorities("USER")
                        .scopes("read.some.thing", "write.some.thing", "any.thing.you.want")
                        .resourceIds(RESOURCE_ID)
                        .secret("your_secret_here");
        }

        @Bean
        @Primary
        public DefaultTokenServices tokenServices() {
            DefaultTokenServices tokenServices = new DefaultTokenServices();
            tokenServices.setSupportRefreshToken(true);
            tokenServices.setTokenStore(tokenStore ());
            return tokenServices;
        }

        @Bean
        public TokenStore tokenStore() {
            return new InMemoryTokenStore();
        }

    }

}

但是,建议不要将这项拨款用于基于web的应用程序。因为你不能保护你的
秘密
。我正在为我的AngularJS web应用程序使用
implicit
grant类型。

您能否提供一个示例代码段,其中我们对用户凭据进行自定义身份验证(即使用自定义身份验证服务),并在成功身份验证时生成一个具有到期时间的访问令牌。然后,该访问令牌可用于AngularJS web应用程序使用的其他rest端点的后续授权。您能否提供一个示例代码段,其中我们对用户凭据进行了自定义身份验证(即使用自定义身份验证服务)以及在成功认证时生成具有到期时间的访问令牌。然后,该访问令牌可用于AngularJS web应用程序使用的其他rest端点的后续授权