Skip to content
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

SID and SessionInformation is null in IdToken when AuthorizationService or Userdetails uses Jdbc or Jpa. #1361

Closed
gurneeraj opened this issue Sep 13, 2023 · 8 comments
Assignees
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@gurneeraj
Copy link

gurneeraj commented Sep 13, 2023

While trying to logout from Spring Authorization Server when spring cloud gateway (Oauth2client) calls logout endpoint, I found SID is null because AuthorizationService or Userdetails uses Jdbc or Jpa.

I used UserDetailsService for creating a UserDetails object.

While debugging I found SessionRegistryImpl is returning null SessionInformation. Highlighted line returns null because 'principal(UserDetails)' is different from ones' present in 'principals'.
image

I created a sample which is similar to the issue I am facing right now. When you run the sample, SID will be null but when you comment out JdbcAuthorizationService config SID will be present in IDToken.

https://github.com/gurneeraj/auth-test

@gurneeraj gurneeraj added the type: bug A general bug label Sep 13, 2023
@ramonmalcolm10
Copy link

I had face a similar issue, try commenting out OAuth2AuthorizationService bean. Not sure why when that bean is configured it don’t return any result, the team can investigate further.
FYI you are still able to perform authentication using your UserDetailsService without that bean configured.

@sjohnr
Copy link
Member

sjohnr commented Sep 14, 2023

Here's the related SO question (https://stackoverflow.com/questions/77093539/sid-missing-in-id-token-using-spring-authorization-server) where I asked for this issue to be opened.

@sjohnr sjohnr self-assigned this Sep 14, 2023
@sjohnr
Copy link
Member

sjohnr commented Sep 14, 2023

@gurneeraj I'm currently unable to reproduce your issue. There are no users in the database when the application starts up. Further, it looks like you cloned the demo-authorizationserver sample, but did not include images so I'm currently getting a 404 error on missing images. If I configure /error as permitAll(), I get past that issue but the demo-client succeeds in logging out. I'm going to close this issue for now as I believe you have a mis-configuration on your client. Please review the official samples in this repo to see if you spot any issues with your configuration. If you can provide a sample of your client, please update the stackoverflow question and add a comment and I'll be happy to take a look at possible mis-configurations on the client side.

@sjohnr sjohnr closed this as completed Sep 14, 2023
@sjohnr sjohnr added for: stackoverflow A question that's better suited to stackoverflow.com and removed type: bug A general bug labels Sep 14, 2023
@nucle
Copy link

nucle commented Oct 15, 2023

Hi,
I have the same issue.
I also tried the version from @gurneeraj but without luck.

For testing, I created a simple project:
Auth Test Github

  1. docker compose up -d (postgres container)
  2. start application (liquibase will insert data)
  3. Comment out and uncomment OAuth2AuthorizationService for in-memory or database

More can be found in the README

Please let me know when something does not work.

BR,
nucle

@sjohnr
Copy link
Member

sjohnr commented Oct 16, 2023

@nucle sorry you're having trouble. I looked at your sample, and it is also not minimal. If starting from one of our existing samples, please only make the minimal changes necessary to add a postgres database (adding liquibase also is fine) for the authorization service. There are a number of other changes in your sample, including adding cors, disabling csrf, adding a custom authentication provider, storing the user details in the database, and possibly other changes. Those changes should not be required to reproduce this issue. Please remove them, and I can take another look.

@nucle
Copy link

nucle commented Oct 16, 2023

@sjohnr np I will create a minimal example.
thx

@sroui
Copy link

sroui commented Oct 31, 2023

@ramonmalcolm10, I had the same issue and I fixed it by doing as you did - deleting OAuth2AuthorizationService which is configured in the code from samples

@gurneeraj
Copy link
Author

Hi instead of using userdetailsservice. I used my own custom authorization provider, it solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

5 participants