本文介紹了OAuth 2.0-單資源服務器但多個客戶端應用程序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
問候語,
我想問以下是不是OAuth 2.0的有效用例:
-
授權服務器(單獨)
單個(或多個)資源服務器
多個客戶端應用程序訪問同一資源服務器。
如果這是有效的用例,我們如何使用授權服務器配置多個客戶端。無法使用APPLICATION.PROPERTIES(APPLICATION.YML)進行配置。
security.oauth2.client.client-id=dummy
security.oauth2.client.client-secret=password
或
security:
oauth2:
resource:
token-info-uri: http://localhost:8080/oauth/check_token
client:
client-id: dummy
client-secret: password
在這種情況下,多個客戶端應用程序的正確配置是什么?
推薦答案
因此,如果您有多個客戶端,則可以通過擴展AuthorizationServerConfigurerAdapter
在AuthorizationServer中注冊客戶端詳細信息
以下是如何在內存中注冊客戶端詳細信息的示例:
@EnableAuthorizationServer
@Configuration
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
private final AuthenticationManager authenticationManager;
@Autowired
public AuthServerConfig(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("egen")
.secret("{noop}egensecret")
.authorizedGrantTypes("authorization_code","refresh_token","password")
.scopes("food_read","food_write")
.and()
.withClient("oauthclient")
.secret("{noop}oauthclient-secret")
.authorizedGrantTypes("client_credentials", "refresh_token")
.authorities("ROLE_USER", "ROLE_OPERATOR")
.scopes("food_read");
}
///more code
}
有關詳細信息,請查看我的GitHub回購:
https://github.com/Dovchiproeng/spring-cloud-security-oauth2-poc/blob/master/spring-cloud-secure-auth-server/src/main/java/com/egen/springcloudsecureauthserver/config/AuthServerConfig.java
這篇關于OAuth 2.0-單資源服務器但多個客戶端應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,