我有一个简单的项目,需要以下简单的配置:
我知道API的URI,我不想要任何巨大的东西(我在https://github.com/spring-projects/spring-security-oauth/tree/master/samples上看到了配置),而且它看起来很大。
我可以这样想:
它可以在两个HTTP请求中完成。我只是不想这样做,但是使用“更安全”的方法来代替Security OAuth2。
你能想到我需要做什么“简单”配置才能做到这一点吗?
发布于 2014-03-04 19:31:09
不要让火花样本迷惑你(它做的比你看起来需要的多得多)。this对你来说够简单吗?
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Configuration
@Order(Ordered.LOWEST_PRECEDENCE - 100)
protected static class OAuth2Config extends OAuth2AuthorizationServerConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth.apply(new InMemoryClientDetailsServiceConfigurer())
.withClient("my-trusted-client")
.authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read", "write", "trust")
.accessTokenValiditySeconds(60)
.and()
.withClient("my-client-with-secret")
.authorizedGrantTypes("client_credentials")
.authorities("ROLE_CLIENT")
.scopes("read")
.secret("secret");
// @formatter:on
}
}
}
那是奥斯服务器。客户端也很容易(例如the one in the Spring OAuth project)。P.S.这都是SpringXML2.0的内容(还没有发布),但是我们正在开发它(而且带有XML的OAuth特性并没有那么重)。
注:这类方法击败了OAuth2的对象(webapp客户端不应该收集用户凭据)。您应该考虑使用grant_type=authorization_code
。
https://stackoverflow.com/questions/22179573
复制相似问题