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

Deprecate OidcSession#expiresIn and add new methods #27336

Merged
merged 1 commit into from Aug 23, 2022

Conversation

sberyozkin
Copy link
Member

@sberyozkin sberyozkin commented Aug 17, 2022

Fixes #27122.

This PR:

  • Fixes OidcSession#expiresIn to return a correct Instant representation of the token expiration time
  • Adds a new method which will help users check how long, starting from now, the session will remain valid for.

Testing for a precise duration value is not easy, it is 3 secs (id token lifespan), but I'd like to avoid some random test failures, I think allowing for a ">1 && < 5" margin is reasonable, even for practical purposes.

@geoand Have a look please when you are back :-).

@sberyozkin
Copy link
Member Author

Thanks @gastaldi :-)

@sberyozkin sberyozkin force-pushed the oidc_session_expires_in_fix branch 2 times, most recently from b52ece4 to a9d4120 Compare August 19, 2022 11:58
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for the impl but I added some suggestions regarding the doc.

Instant expiresIn();

/**
* Return an {@linkplain Instant} representing the current session's expiration time
* which is a number of seconds from the epoch of 1970-01-01T0:0:0Z.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this javadoc correct? It looks like the javadoc of expiresIn? I thought we decided to display the actual expiration time here?
which is a number of seconds from the epoch of 1970-01-01T0:0:0Z looks weird.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsmet It is correct, this is what the exp claim value is which is what this Instant captures. System.currentTime() also uses the same epoch as a base

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand really. Isn't this method supposed to return the real expiration time and not something weird? The doc seems to indicate it will be 1970 + 30 minutes (typically) instead of the real expiration time?

I thought it was the original issue we were trying to solve so I might miss something entirely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsmet It is just the way the expiration time is handled for JWT tokens, the epoch is a base. if we take from some other base then we won't be able to correctly compare it against the current time (which is also calculated from the epoch).
From the exp claim definition in the OIDC spec:

Expiration time on or after which the ID Token MUST NOT be accepted for processing. ... Its value is a JSON number representing the number of seconds from 1970-01-01T0:0:0Z".

The same for issuedAt time, etc.

The doc seems to indicate it will be 1970 + 30 minutes

It will be more than 30 mins, it will be more than the current time. If it is less than the current time then the session (token) has expired.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsmet, if you'd like you can do mvn quarkus:dev in security-openid-connect-quickstart and go to the OIDC devUI card, login to KC as alice:alice and check the exp value in the displayed access or ID token...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the ref to the epoch time to avoid the confusion as agreed with Guillaume

@sberyozkin sberyozkin force-pushed the oidc_session_expires_in_fix branch 2 times, most recently from b81f652 to 6bdd606 Compare August 19, 2022 17:21
@sberyozkin sberyozkin changed the title Fix OidcSession#expiresIn and add a new method Deprecate OidcSession#expiresIn and add new methods Aug 19, 2022
@quarkus-bot

This comment has been minimized.

@gsmet gsmet added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Aug 23, 2022
@gsmet gsmet merged commit 3e3bc6e into quarkusio:main Aug 23, 2022
@quarkus-bot quarkus-bot bot added this to the 2.13 - main milestone Aug 23, 2022
@quarkus-bot quarkus-bot bot added kind/bugfix and removed triage/waiting-for-ci Ready to merge when CI successfully finishes labels Aug 23, 2022
@gsmet gsmet modified the milestones: 2.13 - main, 2.12.0.Final Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

io.quarkus.oidc.OidcSession uses Instant to present duration
4 participants