Skip to content

Commit a511171

Browse files
ngocnhan-tran1996jzheaux
authored andcommitted
Add test and update javadoc for CommonOAuth2Provider
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 86550fb commit a511171

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.config.oauth2.client;
1818

19+
import org.springframework.security.config.Customizer;
1920
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2021
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2122
import org.springframework.security.oauth2.client.registration.ClientRegistration.Builder;
@@ -27,7 +28,7 @@
2728
* Common OAuth2 Providers that can be used to create
2829
* {@link org.springframework.security.oauth2.client.registration.ClientRegistration.Builder
2930
* builders} pre-configured with sensible defaults for the
30-
* {@link HttpSecurity#oauth2Login()} flow.
31+
* {@link HttpSecurity#oauth2Login(Customizer)} flow.
3132
*
3233
* @author Phillip Webb
3334
* @since 5.0

config/src/test/java/org/springframework/security/config/oauth2/client/CommonOAuth2ProviderTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -115,6 +115,24 @@ public void getBuilderWhenOktaShouldHaveOktaSettings() {
115115
assertThat(registration.getRegistrationId()).isEqualTo("123");
116116
}
117117

118+
@Test
119+
public void getBuilderWhenXShouldHaveXSettings() {
120+
ClientRegistration registration = build(CommonOAuth2Provider.X);
121+
ProviderDetails providerDetails = registration.getProviderDetails();
122+
assertThat(providerDetails.getAuthorizationUri()).isEqualTo("https://x.com/i/oauth2/authorize");
123+
assertThat(providerDetails.getTokenUri()).isEqualTo("https://api.x.com/2/oauth2/token");
124+
assertThat(providerDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://api.x.com/2/users/me");
125+
assertThat(providerDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo("username");
126+
assertThat(providerDetails.getJwkSetUri()).isNull();
127+
assertThat(registration.getClientAuthenticationMethod())
128+
.isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_POST);
129+
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
130+
assertThat(registration.getRedirectUri()).isEqualTo(DEFAULT_REDIRECT_URL);
131+
assertThat(registration.getScopes()).containsOnly("users.read", "tweet.read");
132+
assertThat(registration.getClientName()).isEqualTo("X");
133+
assertThat(registration.getRegistrationId()).isEqualTo("123");
134+
}
135+
118136
private ClientRegistration build(CommonOAuth2Provider provider) {
119137
return builder(provider).build();
120138
}

0 commit comments

Comments
 (0)