[英]Spring Security OAuth2 simple configuration
我有一個簡單的項目,需要簡單的以下配置:
我知道API的URI,我不想要任何大的東西(我在https://github.com/spring-projects/spring-security-oauth/tree/master/samples上看到了配置)並且看起來很大。
我可以這樣想:
它可以在2個HTTP請求中完成。 我只是不想這樣做,而是使用“更安全”的方式而不是Spring Security OAuth2。
你能想到我需要做什么“簡單”配置才能完成這項工作嗎?
不要讓火花樣品混淆你(它比你似乎需要的更多)。 是這對你很簡單?
@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
}
}
}
那是auth服務器。 客戶端也很簡單(例如Spring OAuth項目中的客戶端)。 PS這是所有Spring OAuth 2.0的東西(尚未發布),但我們正在研究它(而且使用XML配置的1.0功能確實不那么重)。
注意這種方式會破壞OAuth2的對象(webapp客戶端不應該收集用戶憑據)。 您應該考慮使用grant_type=authorization_code
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.