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

Implement custom use_refresh_token #1103

Merged

Conversation

thatsmydoing
Copy link
Contributor

Summary

This is meant to address #646, it lets you customize when to give a refresh token or not. This uses the same context as custom_access_token_expires_in that was added in #1102

access_token_expires_in: 100,
custom_access_token_expires_in: ->(_context) { nil },
refresh_token_enabled?: lambda { |context|
context.scopes == "public" ? true : false

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:

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

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

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))

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]

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)
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 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.

Copy link
Member

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.

NEWS.md Outdated
@@ -6,6 +6,7 @@ upgrade guides.
User-visible changes worth mentioning.

## master
- [#646] Allow customizing use_refresh_token
Copy link
Member

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)
Copy link
Member

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 ?

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)
Copy link
Member

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.

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)
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 renamed it to block here. but I'm keeping the structure so that it remains compatible with how it worked before.

@thatsmydoing
Copy link
Contributor Author

Is this better?

@nbulaj
Copy link
Member

nbulaj commented Jun 8, 2018

Yep, much better. Could you please resolve the conflicts?

@nbulaj nbulaj merged commit bf36149 into doorkeeper-gem:master Jun 9, 2018
@nbulaj
Copy link
Member

nbulaj commented Jun 9, 2018

Thank you very much 👍

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