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 revoked_at to be set in the future, for future expiry #452

Merged
merged 1 commit into from
Aug 18, 2014
Merged

Allow revoked_at to be set in the future, for future expiry #452

merged 1 commit into from
Aug 18, 2014

Conversation

radar
Copy link

@radar radar commented Aug 7, 2014

Hello,

I'm working with IFTTT integration on a project and they've requested that a refresh token is not revoked immediately. I have no idea how to implement this in doorkeeper without setting revoked_at to a future time. I noticed that the revoked? method merely checks if that field is set, and not if that time has yet passed. This PR attempts to rectify that behaviour.

If you know of a better way to keep refresh tokens around, I would love to hear about it.

Thanks!

@tute
Copy link
Contributor

tute commented Aug 7, 2014

It is adviced in the spec that refresh tokens get invalidated: http://tools.ietf.org/html/rfc6749#section-10.4.

However, I am open to discuss if it should be an option, to allow developers to extend longer-lived refresh tokens. Open question for me now, will research.

Regarding revoked_at datetime, it acts indeed as a boolean, with no logic on its value (it's presence imply it was revoked, and it has some extra information). Your use of the attribute would be better named revoke_at.

Do you know why IFTT requests that refresh tokens are not revoked immediately?

@tute
Copy link
Contributor

tute commented Aug 7, 2014

Note: specific bit of code that revokes a refresh token upon use: https://github.com/doorkeeper-gem/doorkeeper/blob/master/lib/doorkeeper/oauth/refresh_token_request.rb#L31-L32

@radar
Copy link
Author

radar commented Aug 7, 2014

Thank you @tute.

IFTTT says:

We have an issue with rollover refresh tokens as the transaction is non-atomic. There is a chance that we’ll make a request to you to obtain a new refresh token yet fail to persist that new token in our datastore.

This means that they may attempt to use an old refresh token, which means that their integration would not work. We would like a way for refresh tokens to not expire immediately, but at some future date ourselves that we set. This way, IFTTT would be able to use any recent token within the system.

@tute
Copy link
Contributor

tute commented Aug 7, 2014

Your solution seems a good workaround (I'd add a configuration option to set when should they get revoked –10.minutes.from_now, etc). It only uses older naming, probably I'd set an alias or something so it reads better. Will continue reading to see if it's a good option to have in master.

Thanks for your input!

@tute
Copy link
Contributor

tute commented Aug 15, 2014

@radar I like your change, can you please fix the tests (there's a type error), and rebase so I merge? Thanks for your work!

@radar
Copy link
Author

radar commented Aug 17, 2014

Thanks @tute. I've force-pushed on my branch now and the commit for this PR has all the tests passing locally for me.

tute added a commit that referenced this pull request Aug 18, 2014
Allow revoked_at to be set in the future, for future expiry
@tute tute merged commit 925c001 into doorkeeper-gem:master Aug 18, 2014
@tute
Copy link
Contributor

tute commented Aug 18, 2014

Thanks! 👍

@francesle
Copy link

@radar @tute Is there a pull request for actually allowing developers to set revoked_at to a future time? I'm also using this gem to integrate with IFTTT and was wondering whether there's a way to achieve that with the current version...

@tute
Copy link
Contributor

tute commented Feb 16, 2015

@francesle see the options:

  • access_token_expires_in
  • custom_access_token_expires_in
  • authorization_code_expires_in

@francesle
Copy link

I'm actually referring to the refresh token. This pull request seems to be the most relevant: #578

@tute
Copy link
Contributor

tute commented Feb 17, 2015

Right, that's WIP right now.

@voltechs
Copy link

For anyone else still struggling with this, the trick for us (we're integrating with IFTTT as well) is to ensure you are using the previous_refresh_token. Make sure you have this column in your oauth_access_tokens table.

See (line 35)

def before_successful_response
refresh_token.transaction do
refresh_token.lock!
raise Errors::InvalidTokenReuse if refresh_token.revoked?
refresh_token.revoke unless refresh_token_revoked_on_use?
create_access_token
end
super
end

and (line 44)
def self.refresh_token_revoked_on_use?
column_names.include?('previous_refresh_token')
end

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.

4 participants