[[webflux-oauth2-client]]
= OAuth2 客户端

Spring Security的OAuth支持允许无需身份验证即可获取访问令牌.  Spring Boot的基本配置如下所示:

[source,yml]
----
spring:
  security:
    oauth2:
      client:
        registration:
          github:
            client-id: replace-with-client-id
            client-secret: replace-with-client-secret
            scope: read:user,public_repo
----

您将需要用在GitHub注册的值替换 `client-id` 和 `client-secret`.

下一步是指示Spring Security您希望充当OAuth2客户端,以便获取访问令牌.

[source,java]
----
@Bean
SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
	http
		// ...
		.oauth2Client(withDefaults());
	return http.build();
}
----

您现在可以利用Spring Security的第26章 <<webclient>>或<<webflux-roac,@RegisteredOAuth2AuthorizedClient>>  支持来获取和使用访问令牌.
