-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ERR_TOO_MANY_REDIRECTS. State parameter not saved in database when oauth2 authorization server issues an authorization code to a client #1370
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
I know it's not the place to make this type of questions (I already made a post on StackOverflow), but I leave them here to further clarify what my problem is.
Please, note that citation of sources for each of the answers is very welcome. |
Sorry, I saw n. 1314 issue comment you guys made about not cross-post between StackOverflow and GitHub. |
I have also created a dead cycle, but I have solved it, and I believe you should have the same problem as me. |
@zhangpan-soft In my case, the problem was different: the access token generated by my authorization server had a "sub" claim value different from the "sub" claim of the id token, as suggested by @sjohnr . After I changed the id token customizer, to make the "sub" claim values match between the 2 tokens, the problem was solved. |
Bug description
I'm not redirected to the client server homepage after I'm successfully authenticated and authorized by the authorization server. More details at Projects behaviour.
To Reproduce
I have implemented an authorization server very similar to the one provided by Spring Documentation, with the following variations:
Maven instead of gradle, as project builder
JRE: jdk1.8.0_xxx
Spring Boot 2.7.12 , Spring Security 5.7.8 , Spring Security oauth2 authorization server 0.4.2 ,
a sql server database to store user's credentials. Here I also implemented the 3 oauth2 tables that, in the Spring demo, are located in an embedded h2 database,
a custom UserDetailsService instead of an InMemoryUserDetailsManager:
Here the SecurityUser class:
Here the SecurityUserMixin class (needed at point n. 7):
I removed the device flow authentication's logic (as I downgraded the authorization server's version to 0.4.2) from the AuthorizationServerConfig class:
As result (and since I applied my own OAuth2TokenCustomizer method), these classes are not included in my project anymore:
FederatedIdentityIdTokenCustomizer
UserRepositoryOauth2UserHandler
DeviceClientAuthenticationProvider
DeviceClientAuthenticationToken
DeviceController
DeviceClientAuthenticationConverter
I modified the Oauth2AuthorizationService method since I had to resolve the issue n. 397:
All other classes of the authorization not mentioned are left unchanged from Spring's ones.
Then I implemented a resource server (built with Maven) and a client server (built with Gradle). Both are very similar to those of Spring, but, in the client, I remove device flow authentication logic.
To implement the 3 oauth2 tables I used the default sql scripts for this authorization server version, but I replaced every blob type column with varchar and every timestamp type column with datetime.
To build the authorization server and the resource server I used this maven build command: spring-boot:run.
Projects behaviour and error:
All 3 projects build up correctly, and the registered client configured in my authorization server is saved in the oauth2_registered_client table.
Via browser, I try to access the client server homepage and I'm (correctly) redirected to the authorization server. Here I authenticate with the credentials of a previously registered user, and I'm redirected to the consent page. If I check the database queries in the project logs I see an INSERT INTO oauth2_authorization table query, with a state value, but, if I check the table on the database, no records are available.
In the consent page, the only consent available is profile and after I select that and submit the form, the authorization server goes in a loop where it continues to issue new authorization codes, one every second, and on the browser I get the ERR_TOO_MANY_REDIRECTS error.
In the project's logs (
logging.level.org.springframework.security: TRACE
) I see no errors: after the GET and POST /oauth2/authorize, the POST oauth2/token, the GET /oauth2/jwks and the GET /userinfo requests, the projects starts again to secure the GET /oauth2/authorize with a different authorization code (and state value!) from the same previous GET.On the network tab on DevTools, I see some redirects to ...login/code/messaging-client-oidc with different authorization codes and state values, I stop the loading of the page (as I know that would generate the error I mentioned), and if I check the oauth2_authorization table on my database I see a bunch of records with different authorization codes but everyone with a NULL state.
However, If I try to reach one of my resource server endpoints via Postman, the authentication and authorization flow works and I get an access_token after I select the consents required. But still, no state value is saved in the record on the oauth2_authorization table.
Apart from this, if I stopped my authorization server and I plug the Spring one, the authorization flow works perfectly and I'm redirect to the client homepage as expected.
Expected behavior
After I select the profile consent via browser, I should be redirected to the client server homepage, and I should only have one record on the oauth2_authorization table with a valid state value.
The text was updated successfully, but these errors were encountered: