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

oauth2: Add custom TTL to refresh tokens #2942

Merged

Conversation

bob983
Copy link
Contributor

@bob983 bob983 commented Oct 9, 2017

Summary

Refresh token TTL used to be hardcoded to 14 days. This pose a problem with scenarios where the token/refresh_token is only used sporadically. This PR adds new config option refresh_token_ttl that specify refresh token's TTL. If the value is nil or 0 it means keep forever.

  • add refresh_token_ttl to the plugin's schema
  • pass the value down to generate_token method as ttl option, replace it with nil if the is either not defined or lower than 0.
  • add schema spec test
  • add access spec test
  • update documentation - that's a separate PR I guess

Full changelog

kong/plugins/oauth2/schema.lua
kong/plugins/oauth2/access.lua

Test cases

spec/03-plugins/26-oauth2/01-schema_spec.lua
spec/03-plugins/26-oauth2/03-access_spec.lua

Issues resolved

Fix #2024

Misc

I'm of course open to suggestion on how to make the code better or how to test it better

@bob983
Copy link
Contributor Author

bob983 commented Oct 9, 2017

OK, I tuned the tests against 0.10.3, because that's what we are using, but one of the helpers that I used is now somewhere else in current master. I'll have a look at it 👁

@bob983 bob983 force-pushed the feat/plugins/oauth2/refresh-token-ttl branch 3 times, most recently from 126d113 to 72e62a9 Compare October 9, 2017 21:33
@@ -31,6 +31,7 @@ return {
accept_http_if_already_terminated = { required = false, type = "boolean", default = false },
anonymous = {type = "string", default = "", func = check_user},
global_credentials = {type = "boolean", default = false},
refresh_token_ttl = {required = false, type = "number", default = 1209600} -- original hardcoded value - 14 days
Copy link
Member

Choose a reason for hiding this comment

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

Do not allow nil here, so required = true.

This also means that a migration is needed to insert the default value in all existing entries, see this code for an example.

Because of the migration, we also cannot target the master branch, but must go to the next major release, which is in the next branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, gotcha, let me add the required flag, the migration and rebase/switch to next branch.

@bob983 bob983 changed the base branch from master to next October 11, 2017 13:29
@bob983 bob983 force-pushed the feat/plugins/oauth2/refresh-token-ttl branch from 72e62a9 to a709b4d Compare October 11, 2017 14:24
@bob983
Copy link
Contributor Author

bob983 commented Oct 11, 2017

@Tieske I added the migration, rebased against next and set the required option to true

Tieske
Tieske previously requested changes Oct 23, 2017
Copy link
Member

@Tieske Tieske left a comment

Choose a reason for hiding this comment

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

too much copy-pasta 😄

return config
end
if config.run_on_preflight == nil then
config.run_on_preflight = true
Copy link
Member

Choose a reason for hiding this comment

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

too much copy-pasta here, run_on_preflight is not being added here but the config option refresh_token_ttl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤕 oh my, Bob! Thanks

@bob983 bob983 force-pushed the feat/plugins/oauth2/refresh-token-ttl branch 2 times, most recently from 520e5c0 to fe143a7 Compare October 23, 2017 12:42
@bob983
Copy link
Contributor Author

bob983 commented Oct 23, 2017

OK, let's pretend the migration code didn't contain run_on_preflight config option ...

@Tieske
Copy link
Member

Tieske commented Oct 23, 2017

final item seems docs, on https://github.com/Kong/getkong.org

@bob983
Copy link
Contributor Author

bob983 commented Oct 25, 2017

Updated documentation - Kong/docs.konghq.com#535

@Tieske
Copy link
Member

Tieske commented Oct 25, 2017

This crossed another PR and now needs a rebase

Refresh token TTL used to be hardcoded to 14 days. This pose a problem with scenarios where the token/refresh_token is only used sporadically. This change adds new config option refresh_token_ttl that specify refresh token's TTL. If the value is nil or 0 it means keep forever.

Fix Kong#2024
@bob983 bob983 force-pushed the feat/plugins/oauth2/refresh-token-ttl branch from fe143a7 to 735f72d Compare October 31, 2017 12:56
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

I think this will do it. There are many aspects to this plugins that warrant a refactor/improvement but they would be outside the scope of this PR, which I think is suffering from it.

Thank for contributing this feature @bob983!

@thibaultcha thibaultcha dismissed Tieske’s stale review November 1, 2017 23:44

required changes addressed by contributor

@thibaultcha thibaultcha merged commit 8b86700 into Kong:next Nov 1, 2017
@thibaultcha
Copy link
Member

Thank you for the contribution @bob983 ! This shall be released in our next major version (0.12).

@bob983 bob983 deleted the feat/plugins/oauth2/refresh-token-ttl branch December 1, 2017 16:43
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Dec 19, 2017
See Kong/kong#2942
From #535

Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Jan 12, 2018
See Kong/kong#2942
From #535

Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Jan 16, 2018
See Kong/kong#2942
From #535

Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Jan 16, 2018
See Kong/kong#2942
From #535

Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
thibaultcha pushed a commit that referenced this pull request Jan 16, 2018
A `refresh_token` TTL used to be hard-coded to 14 days.

This pose a problem with scenarios where the token/refresh_token
is only used sporadically. This change adds new config option
`refresh_token_ttl` that specifies a refresh token's TTL. If the value
is `nil` or 0, it means keep forever.

Fix #2024
From #2942
thibaultcha pushed a commit that referenced this pull request Jan 19, 2018
A `refresh_token` TTL used to be hard-coded to 14 days.

This pose a problem with scenarios where the token/refresh_token
is only used sporadically. This change adds new config option
`refresh_token_ttl` that specifies a refresh token's TTL. If the value
is `nil` or 0, it means keep forever.

Fix #2024
From #2942
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