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

Allow for expired refresh tokens to be revoked #1744

Conversation

ransombriggs
Copy link
Contributor

Summary

This alters the revocation endpoint so that when a refresh token is revoked, we check revoked? rather than accessible? since the extra expired? check in accessible? does not apply to refresh tokens since they never expire.

#1743

token_and_type&.[](:type)
end

def token_and_type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I admit that this implementation is pretty awkward, I went with the simplest / quickest just to show the issue. I think I would rather create an object here that is the pair instead, but not sure if y'all would think that is overkill or would match your patterns, just let me know and I can refactor this however you want it to look.

Copy link
Member

Choose a reason for hiding this comment

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

Agree, maybe better to have some clear DTO object. Can we refactor it please? 🙏 We have some (well not good actually) examples like OAuth::Client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went a slightly different direction and refactored in 5dd6454 into classes that respond to revocable? and revoke. I think it is cleaner than this the original code, but can keep tweaking.

@@ -113,19 +113,53 @@ def revoke_token
# The authorization server responds with HTTP status code 200 if the token
# has been revoked successfully or if the client submitted an invalid
# token
token.revoke if token&.accessible?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have already checked token.blank? by the time we call this so the &. felt unnecessary, but I can bring it back.

@@ -183,8 +191,89 @@
expect(response.status).to eq 200
end

it "revokes the access token" do
post :revoke, params: { client_id: client.uid, token: access_token.token }
it "does not revoke the access token when token_type_hint == refresh_token" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The token method was not fully tested so added some specs before I made my changes.

@ransombriggs ransombriggs requested a review from nbulaj November 11, 2024 19:26
Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 🙇

@nbulaj
Copy link
Member

nbulaj commented Dec 2, 2024

@ransombriggs can we please squash all the commits into a single one for the clear history? 🙏 Thanks!

@ransombriggs ransombriggs force-pushed the allow-refresh-tokens-to-be-revoked-after-expire branch from 1503e70 to eab3e3b Compare December 2, 2024 16:09
@ransombriggs
Copy link
Contributor Author

@nbulaj I rebased main and squashed the commits in eab3e3b

end

def revocable_token
return @revocable_token if defined? @revocable_token
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this? instead of 124...126?

Suggested change
return @revocable_token if defined? @revocable_token
@revocable_token ||= begin ... end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with the defined? pattern so that nil is memozied properly in the case where the token cannot be found.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah! my bad. thank you.

@nbulaj nbulaj merged commit 9e91717 into doorkeeper-gem:main Dec 5, 2024
22 checks passed
@nbulaj
Copy link
Member

nbulaj commented Dec 5, 2024

Thanks a lot @ransombriggs ! 🙇

@ransombriggs ransombriggs deleted the allow-refresh-tokens-to-be-revoked-after-expire branch December 5, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants