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

fix(tokens): Fixes the potential of deleting a working refresh_token when no new one is available #406

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

drzraf
Copy link
Contributor

@drzraf drzraf commented May 23, 2022

All Submissions:

Changes proposed in this Pull Request:

save_refresh_token() disregard the existing and still valid refresh_token and replace it with false (since the response to a renewal does not contain it)

Closes #404

How to test the changes in this Pull Request:

  1. Use Google OIDC with refresh token
        add_filter( 'openid-connect-generic-auth-url', function( string $url ) {
            return $url . '&access_type=offline&prompt=consent';
        });
  1. Connect
  2. See from your logs that, without this PR you're disconnect after 1h (the first call torefresh_token)

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

Do not empty refresh_token if renewed access tokens do not come with new refresh_token.

@drzraf
Copy link
Contributor Author

drzraf commented Jun 27, 2022

ping?

@drzraf
Copy link
Contributor Author

drzraf commented Aug 8, 2022

We have been using this in -production to fix our GSuite 1h-disconnection problems and this has been confirmed to work.

@timnolte timnolte self-assigned this Aug 8, 2022
@timnolte timnolte added the status: needs review PR that needs review. label Aug 8, 2022
@drzraf
Copy link
Contributor Author

drzraf commented Apr 24, 2023

ping

@timnolte timnolte added the bug label May 23, 2023
@timnolte timnolte changed the title Don't delete a working refresh_token if no new one is available fix(tokens): Fixes the potential of deleting a working refresh_token when no new one is available May 23, 2023
@timnolte timnolte added this to the 3.9.2 milestone May 23, 2023
@timnolte
Copy link
Collaborator

@drzraf so actually, in doing some digging on this subject to make sure that things are being handled properly, and to specs. I happened upon an actual reason for why you were having this issue. It has been on the table to quite some time to replace much of the core functionality with a standard Composer package. I happened upon this issue:

jumbojett/OpenID-Connect-PHP#286

Which further took me here:

https://stackoverflow.com/a/65702100

Basically, what is happening is that once you authenticate the first time with Google you won't get a new refresh token un later requests without using prompt=consent or approval_prompt=force and access_type=offline. This is apparently not well documented with Google/GSuite. I'm not inclined to include this PR as I think there is more to the fix that is really required.

@timnolte timnolte added status: blocked Issue or PR is blocked. and removed status: needs review PR that needs review. labels May 24, 2023
@timnolte timnolte modified the milestones: 3.9.2, 3.10.0 May 24, 2023
@timnolte
Copy link
Collaborator

An additional follow-up that I happened to come across this MU Plugin that is essentially an add-on for this plugin that addresses the Google refresh token issue.

https://gitlab.com/animalequality/wp-openid/-/blob/master/wp-openid.php

@drzraf
Copy link
Contributor Author

drzraf commented May 25, 2023

https://gitlab.com/animalequality/wp-openid/-/blob/master/wp-openid.php

I wrote this code, and having a filter to customize the request (adding prompt=consent) is nice but it doesn't free this plugin from the responsibility of behaving correctly by not emptying an existing/valid refresh token which is what this PR is about.

@timnolte
Copy link
Collaborator

@drzraf from what I see this isn't some clear problem specifically with this plugin as an issue with Google specifically. I didn't close the PR or issue I simply postponed it until I can find some very clear documentation on all of the handling and can test with other IDPs. The very fact the the code submitted has a comment regarding the scenario of what if the token was actually expired and the comment said "dunno" is not a very confident response to the proper way this should be handled.

All of the notes I made were in regards to doing actual research into this issue to ensure that the correct solution is implemented and not just something that appears to be a fox for 1 IDP or use case.

@timnolte timnolte deleted the branch oidc-wp:develop December 23, 2023 00:56
@timnolte timnolte closed this Dec 23, 2023
@timnolte timnolte reopened this Dec 23, 2023
@timnolte timnolte changed the base branch from dev to develop December 23, 2023 01:15
@timnolte timnolte modified the milestones: 3.10.0, 3.10.1 Apr 25, 2024
@timnolte timnolte removed this from the 3.10.1 milestone May 7, 2024
@timnolte timnolte added this to the 3.10.1 milestone May 10, 2024
@czarny
Copy link

czarny commented Nov 23, 2024

Hi it is not matter only of one IDP. AWS Cognito also does not have refresh tokens rotation and that is fine with spec. See https://datatracker.ietf.org/doc/html/rfc6749#section-6

The authorization server MAY issue a new refresh token, in which case
the client MUST discard the old refresh token and replace it with the
new refresh token.
@drzraf I think you should update your pull request. Especially comments. If token is expired auth server will return error and plugin will end user session.

@drzraf
Copy link
Contributor Author

drzraf commented Nov 24, 2024

Just to remind the actual use-case: My users connect to WP using GSuite. Without such a modification of the refresh-token handling, they get disconnected after one hour what is understandably problematic and frustrating. I didn't read the standards and whether IDP is in charge of disconnecting (IMHO identity providing <> session management/duration).

@timnolte
Copy link
Collaborator

Just to remind the actual use-case: My users connect to WP using GSuite. Without such a modification of the refresh-token handling, they get disconnected after one hour what is understandably problematic and frustrating. I didn't read the standards and whether IDP is in charge of disconnecting (IMHO identity providing <> session management/duration).

@drzraf so it's very possible the refresh token issue you are seeing is due to a different bug that has already been fixed but it hasn't been released for this version of the plugin. If you install the version I linked to in the pinned issue about no more updates going to WP.org you might find that your 1 hour timeout issue is fixed.

https://github.com/forumone/openid-connect-wp-dist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status: blocked Issue or PR is blocked.
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

save_refresh_token may delete valid refresh_token and break refresh functionality
3 participants