-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement custom use_refresh_token #1103
Implement custom use_refresh_token #1103
Conversation
spec/lib/oauth/base_request_spec.rb
Outdated
access_token_expires_in: 100, | ||
custom_access_token_expires_in: ->(_context) { nil }, | ||
refresh_token_enabled?: lambda { |context| | ||
context.scopes == "public" ? true : false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/RedundantConditional: This conditional expression can just be replaced by context.scopes == "public".
# Issue access tokens with refresh token (disabled by default) | ||
# Issue access tokens with refresh token (disabled by default), you may also | ||
# pass a block which accepts `context` to customize when to give a refresh token | ||
# or not. Similar to `custom_access_token_expires_in`, `context` has the properties: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [86/80]
@@ -66,7 +66,13 @@ | |||
# | |||
# reuse_access_token | |||
|
|||
# Issue access tokens with refresh token (disabled by default) | |||
# Issue access tokens with refresh token (disabled by default), you may also | |||
# pass a block which accepts `context` to customize when to give a refresh token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [82/80]
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UselessAccessModifier: Useless private access modifier.
end | ||
|
||
def access_token_expires_in(server, context) | ||
if (expiration = server.custom_access_token_expires_in.call(context)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [81/80]
lib/doorkeeper/config.rb
Outdated
def use_refresh_token | ||
@config.instance_variable_set(:@refresh_token_enabled, true) | ||
# Issue access tokens with refresh token (disabled if not set) | ||
def use_refresh_token(enabled = true, &custom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the enabled = true
parameter here in case people do use_refresh_token false
. Since this takes a block parameter, I thought to make it a bit consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer &block
instead of &custom
as a common practice, what do you think?
Also check out force_ssl_in_redirect_uri
option and how it works with block or boolean variables.
7c5fbab
to
38ca199
Compare
NEWS.md
Outdated
@@ -6,6 +6,7 @@ upgrade guides. | |||
User-visible changes worth mentioning. | |||
|
|||
## master | |||
- [#646] Allow customizing use_refresh_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix it to #1103 please, it addresses the real PR that made changes
private | ||
|
||
def custom_expiration(server, pre_auth_or_oauth_client, grant_type, scopes) | ||
def make_context(pre_auth_or_oauth_client, grant_type, scopes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rename it to build_context
?
lib/doorkeeper/config.rb
Outdated
def use_refresh_token | ||
@config.instance_variable_set(:@refresh_token_enabled, true) | ||
# Issue access tokens with refresh token (disabled if not set) | ||
def use_refresh_token(enabled = true, &custom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer &block
instead of &custom
as a common practice, what do you think?
Also check out force_ssl_in_redirect_uri
option and how it works with block or boolean variables.
38ca199
to
de9e894
Compare
def use_refresh_token | ||
@config.instance_variable_set(:@refresh_token_enabled, true) | ||
# Issue access tokens with refresh token (disabled if not set) | ||
def use_refresh_token(enabled = true, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it to block here. but I'm keeping the structure so that it remains compatible with how it worked before.
Is this better? |
Yep, much better. Could you please resolve the conflicts? |
de9e894
to
e42ee06
Compare
Thank you very much 👍 |
Summary
This is meant to address #646, it lets you customize when to give a refresh token or not. This uses the same
context
ascustom_access_token_expires_in
that was added in #1102