-
Notifications
You must be signed in to change notification settings - Fork 6k
Form Login not possible when a single OAuth2 Provider is configured #6802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report @netmikey. Would you be interested in submitting a PR for this fix? |
I could work on this if @netmikey didn't want to 👍 |
@rhamedy Nothing that comes to mind at the moment. But feel free to ask any questions along the way. Thanks for taking this on. |
Hi @jgrandja I wanted to run these changes and questions by you before creating a pull request. For the actual issue pointed out in the description of the ticket, I did the following
to following and verified it with a test 👍
I could not find an alternative Secondly, I noticed that the same issue is there in the reactive side as well. Assuming that the
to
however I am not sure if
The error snippet is as follow
I am new to |
@rhamedy I would like to avoid the I would leave the reactive changes out for now. Let's figure out the apprach for the fix on servlet side first and go from there. |
Sounds good @jgrandja, I will look into other options 👍 |
@rhamedy If you look at the logic in |
@netmikey As a temporary workaround, you can configure The auto-redirect only happens when there is one client configured and no custom |
I know, and I'm working on a custom login already. The default form is very convenient for starting development though, and I found its behavior confusing, especially for someone starting on that subject. |
hi @jgrandja last week I spent some quite some time debugging alternative options and a majority of my attempts resulted it either in
That above test breaks with no fix 👍 and then I proceeded with adding alternative fixes to
With the above fix the newly added test above passes ✅ however, an existing test fails the assertions and the question to ask is it correct for In your suggestions you mentioned making use of
Not sure if that is going to help since it's not just I wanted to specifically check if the filter chain includes This I might have to do a Sorry for the detailed messages, it does not seem to be a straight curve and I am starting to feel that my limited knowledge of |
Take a look at My original suggestion on checking This is a tricky one for sure. At the moment, I don't have another suggestion but will give this some further thought. |
Make sense. I will give it some more thoughts in the coming days and will update here. |
Is there some way to customize loginPage when we use oauth2Login? In the servlet configuration it is allowed by using this:
But using ServerHttpSecurity |
Hey everyone. I've read through the comments to catch up on this issue. Before looking to a fix, I wanted to see if I understood the issue correctly. So far, with a hello-world style app, I seem to be able to get the desired behavior to work, so I'm wondering if I'm missing anything. Here's what I have: First, I ran auth-server from @jgrandja 's oauth2-protocol-patterns to stand in for okta, facebook, google, etc. Note: I've added an entry to Second, I stood up a spring boot app with the following:
server:
port: 8080
spring:
security:
oauth2:
client:
registration:
login-client:
provider: spring
client-id: login-client
client-secret: secret
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope: openid
provider:
spring:
issuer-uri: http://auth-server:9000
user:
password: "{noop}password"
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.loginPage("/login")
.and()
.oauth2Client()
.and()
.formLogin()
.permitAll()
.and();
}
@Bean
public UserDetailsService userDetailsService(SecurityProperties securityProperties) {
SecurityProperties.User user = securityProperties.getUser();
UserDetails userDetails = User.withUsername(user.getName())
.password(user.getPassword())
.roles(user.getRoles().toArray(new String[0]))
.build();
return new InMemoryUserDetailsManager(userDetails);
}
}
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
public class HomeController {
@GetMapping("/")
public Map<String, String> hello() {
return Map.of("greeting", "Hello, World");
}
} You'll notice I had to work through an issue with the auto-configured If I visit If I visit I have not tried anything with the oauth client yet. If you all (@netmikey, @rhamedy, or @dcoraboeuf) have any thoughts on what I'm missing to reproduce your particular issue, let me know. @jarpz, would you mind opening a separate issue (if one doesn't already exist) on that? Update: One additional note: If I configure @Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.loginPage("/oauth2/authorization/login-client")
.and()
.oauth2Client()
.and()
.formLogin()
.permitAll()
.and();
} Does this achieve the desired behavior in the opening comment? |
@sjohnr To reproduce the issue, change your From: protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.loginPage("/login")
.and()
.oauth2Client()
.and()
.formLogin()
.permitAll()
.and();
} To: protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.oauth2Client()
.and()
.formLogin()
.permitAll()
.and();
} Removing Makes sense? |
The problem I reported is when we use WebFlux Security configuration, In that case, we are not allowed to "change" the default generated webpage for oauth2Client, like when you use "mvc" security adapter does. It seems both forms of build security expression are not equivalent. they don't have the same methods. Regards |
This is a question that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements.
If a feature is missing in |
Summary
When using a Form Login, a single OAuth2 provider and the auto-generated login page, the auto-configured
AuthenticationEntryPoint
will redirect to the provider immediately, bypassing the login page and effectively preventing form login.Actual Behavior
When trying to access a protected resource, spring security will immediately redirect to the OAuth2 provider's authentication page instead of the local login page.
Expected Behavior
When Form Login is configured, the login page should never be skipped.
Configuration
Version
5.1.4-RELEASE, not sure as of which version this happens.
Sample
I don't have a sample, but I found the exact location of the bug:
spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Lines 444 to 453 in 2c136f7
The condition should check whether Form Login is enabled and don't apply the shortcut if it is.
The text was updated successfully, but these errors were encountered: