不要让sparklr样本使您感到困惑(它所做的远远超出您的预期)。就是这个简单的够吗?
@ComponentScan@EnableAutoConfigurationpublic 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_pre", "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 }}}
那就是认证服务器。客户端也很容易(例如Spring OAuth项目中的客户端)。PS这是Spring
OAuth 2.0的全部内容(尚未发布),但是我们正在努力(而XML配置的1.0功能确实没有那么重)。
注意:这种方式击败了OAuth2的对象(Webapp客户端 不
应该收集用户凭据)。您应该考虑使用
grant_type=authorization_pre。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)