Skip to content

Commit d92d3a9

Browse files
committed
Clarify inferred relationships between registrations and providers
Closes gh-49240
1 parent 5a76416 commit d92d3a9

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ private void validateRegistration(String id, Registration registration) {
7676
public static class Registration {
7777

7878
/**
79-
* Reference to the OAuth 2.0 provider to use. May reference an element from the
80-
* 'provider' property or used one of the commonly used providers (google, github,
81-
* facebook, okta).
79+
* Reference to the OAuth 2.0 provider to use. May reference one of the common
80+
* providers (google, github, facebook, okta) or the ID of a custom provider
81+
* configured using 'spring.security.oauth2.client.provider.<id>.*'
82+
* properties. When not set, the ID of this registration is used to identify the
83+
* provider.
8284
*/
8385
private String provider;
8486

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/web/spring-security.adoc

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,33 @@ If you have `spring-security-oauth2-client` on your classpath, you can take adva
101101
This configuration makes use of the properties under javadoc:org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties[].
102102
The same properties are applicable to both servlet and reactive applications.
103103

104+
Each registration must specify an OAuth 2 provider.
105+
When set, the value of the `spring.security.oauth2.client.registration.<registration-id>.provider` property is used to specify the registration's provider.
106+
If the `provider` property is not set, the registration's ID is used instead.
107+
Both approaches are shown in the following example:
108+
109+
[configprops,yaml]
110+
----
111+
spring:
112+
security:
113+
oauth2:
114+
client:
115+
registration:
116+
my-client:
117+
client-id: "abcd"
118+
client-secret: "password"
119+
provider: "example"
120+
example:
121+
client-id: "abcd"
122+
client-secret: "password"
123+
----
124+
125+
The registrations `my-client` and `example` will both use the provider with ID `example`.
126+
The former will do so due to the value of the `spring.security.oauth2.client.registration.my-client.provider` property.
127+
The latter will do so due to its ID being `example` and there being no `provider` property configured for the registration.
128+
129+
The specified provider can either be a reference to a provider configured using `spring.security.oauth2.client.provider.<provider-id>.*` properties or one of the xref:web/spring-security.adoc#web.security.oauth2.client.common-providers[known common providers].
130+
104131
You can register multiple OAuth2 clients and providers under the `spring.security.oauth2.client` prefix, as shown in the following example:
105132

106133
[configprops,yaml]
@@ -150,6 +177,10 @@ spring:
150177
user-name-attribute: "name"
151178
----
152179

180+
In this example, there are three registrations.
181+
In order of declaration, their IDs are `my-login-client`, `my-client-1`, and `my-client-2`.
182+
There is also a single provider with ID `my-oauth-provider`.
183+
153184
For OpenID Connect providers that support https://openid.net/specs/openid-connect-discovery-1_0.html[OpenID Connect discovery], the configuration can be further simplified.
154185
The provider needs to be configured with an `issuer-uri` which is the URI that it asserts as its Issuer Identifier.
155186
For example, if the `issuer-uri` provided is "https://example.com", then an "OpenID Provider Configuration Request" will be made to "https://example.com/.well-known/openid-configuration".
@@ -182,12 +213,12 @@ For production environments, consider using a javadoc:org.springframework.securi
182213
[[web.security.oauth2.client.common-providers]]
183214
==== OAuth2 Client Registration for Common Providers
184215

185-
For common OAuth2 and OpenID providers, including Google, Github, Facebook, and Okta, we provide a set of provider defaults (`google`, `github`, `facebook`, and `okta`, respectively).
186-
187-
If you do not need to customize these providers, you can set the `provider` attribute to the one for which you need to infer defaults.
188-
Also, if the key for the client registration matches a default supported provider, Spring Boot infers that as well.
216+
For common OAuth2 and OpenID providers (Google, Github, Facebook, and Okta), we provide a set of provider defaults.
217+
The IDs of these common provides are `google`, `github`, `facebook`, and `okta`, respectively.
189218

190-
In other words, the two configurations in the following example use the Google provider:
219+
If you do not need to customize these providers, set the registration's `provider` property to the ID of one of the common providers.
220+
Alternatively, you can xref:web/spring-security.adoc#web.security.oauth2.client[use a registration ID that matches the ID of the provider].
221+
The two configurations in the following example use the common `google` provider:
191222

192223
[configprops,yaml]
193224
----

0 commit comments

Comments
 (0)