Skip to content

Commit ff8b77d

Browse files
authored
Add Twitter/X to CommonOAuth2Provider
Add Twitter/X to CommonOAuth2Provider
2 parents 48eb243 + 693a5be commit ff8b77d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

config/src/main/java/org/springframework/security/config/oauth2/client/CommonOAuth2Provider.java

+17
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ public Builder getBuilder(String registrationId) {
8787

8888
},
8989

90+
X {
91+
92+
@Override
93+
public Builder getBuilder(String registrationId) {
94+
ClientRegistration.Builder builder = getBuilder(registrationId,
95+
ClientAuthenticationMethod.CLIENT_SECRET_POST, DEFAULT_REDIRECT_URL);
96+
builder.scope("users.read", "tweet.read");
97+
builder.authorizationUri("https://x.com/i/oauth2/authorize");
98+
builder.tokenUri("https://api.x.com/2/oauth2/token");
99+
builder.userInfoUri("https://api.x.com/2/users/me");
100+
builder.userNameAttributeName("username");
101+
builder.clientName("X");
102+
return builder;
103+
}
104+
105+
},
106+
90107
OKTA {
91108

92109
@Override

docs/modules/ROOT/pages/reactive/oauth2/login/core.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ A `ClientRegistration` can be initially configured using discovery of an OpenID
153153
[[webflux-oauth2-login-common-oauth2-provider]]
154154
== CommonOAuth2Provider
155155

156-
`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, and Okta.
156+
`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, X, and Okta.
157157

158158
For example, the `authorization-uri`, `token-uri`, and `user-info-uri` do not change often for a Provider.
159159
Therefore, it makes sense to provide default values in order to reduce the required configuration.

docs/modules/ROOT/pages/servlet/oauth2/login/core.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ You can initially configure a `ClientRegistration` by using discovery of an Open
153153
[[oauth2login-common-oauth2-provider]]
154154
== CommonOAuth2Provider
155155

156-
`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, and Okta.
156+
`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, X, and Okta.
157157

158158
For example, the `authorization-uri`, `token-uri`, and `user-info-uri` do not change often for a provider.
159159
Therefore, it makes sense to provide default values, to reduce the required configuration.

0 commit comments

Comments
 (0)