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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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.

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.

2 participants