Переглянути джерело

Add Twitter/X to CommonOAuth2Provider

Add Twitter/X to CommonOAuth2Provider
Rob Winch 3 місяців тому
батько
коміт
ff8b77df29

+ 17 - 0
config/src/main/java/org/springframework/security/config/oauth2/client/CommonOAuth2Provider.java

@@ -87,6 +87,23 @@ public enum CommonOAuth2Provider {
 
 	},
 
+	X {
+
+		@Override
+		public Builder getBuilder(String registrationId) {
+			ClientRegistration.Builder builder = getBuilder(registrationId,
+					ClientAuthenticationMethod.CLIENT_SECRET_POST, DEFAULT_REDIRECT_URL);
+			builder.scope("users.read", "tweet.read");
+			builder.authorizationUri("https://x.com/i/oauth2/authorize");
+			builder.tokenUri("https://api.x.com/2/oauth2/token");
+			builder.userInfoUri("https://api.x.com/2/users/me");
+			builder.userNameAttributeName("username");
+			builder.clientName("X");
+			return builder;
+		}
+
+	},
+
 	OKTA {
 
 		@Override

+ 1 - 1
docs/modules/ROOT/pages/reactive/oauth2/login/core.adoc

@@ -153,7 +153,7 @@ A `ClientRegistration` can be initially configured using discovery of an OpenID
 [[webflux-oauth2-login-common-oauth2-provider]]
 == CommonOAuth2Provider
 
-`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, and Okta.
+`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, X, and Okta.
 
 For example, the `authorization-uri`, `token-uri`, and `user-info-uri` do not change often for a Provider.
 Therefore, it makes sense to provide default values in order to reduce the required configuration.

+ 1 - 1
docs/modules/ROOT/pages/servlet/oauth2/login/core.adoc

@@ -153,7 +153,7 @@ You can initially configure a `ClientRegistration` by using discovery of an Open
 [[oauth2login-common-oauth2-provider]]
 == CommonOAuth2Provider
 
-`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, and Okta.
+`CommonOAuth2Provider` pre-defines a set of default client properties for a number of well known providers: Google, GitHub, Facebook, X, and Okta.
 
 For example, the `authorization-uri`, `token-uri`, and `user-info-uri` do not change often for a provider.
 Therefore, it makes sense to provide default values, to reduce the required configuration.