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

Further refactor of token creation #1098

Merged
merged 2 commits into from
Feb 22, 2018

Conversation

Evan-M
Copy link
Collaborator

@Evan-M Evan-M commented Feb 21, 2018

I commented on #1061 after it was merged, but since I'm not sure I was very clear, I went ahead and further refactored things to DRY up the code a bit more.

Essentially, the #create_token method can accept arbitrary additional keyword attributes that will be merged into the resulting tokens[client_id] hash. This allows #create_new_auth_token to reuse the token creation logic, instead of duplicating it. See: e601951 for details.

Note the first commit of this PR is misc cleanup, and perhaps doesn't belong.

I didn't add additional tests, since there is no additional functionality.

 - Rewrite terse code.
 - Remove superfluous implicit calls to self.
 - Move instance method out of `included do...` block.
 - Optionally accept extra attributes hash when calling `#create_token`.
 - Utilize token_extras hash for `#create_token` to DRY up `#create_new_auth_token`.
 - Synchronize the time used to set `expiry` and `updated_at`.
@Evan-M Evan-M mentioned this pull request Feb 21, 2018
@zachfeldman
Copy link
Contributor

Hey @Evan-M thanks for this! Your refactorings make sense and I get what you're doing here. If one other person approves this PR I'll merge it.

@zachfeldman zachfeldman self-requested a review February 21, 2018 14:39
end
def email_required?; false; end
def email_changed?; false; end
def will_save_change_to_email?; false; end

Choose a reason for hiding this comment

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

These unexplained devise overrides are the bane of my existence and the cause of a lot of hair pulling for a lot of developers... But alas, you aren't changing their functionality here.

That said, I'd just leave these alone, so we can preserve our git blame history on these three methods to help the next poor soul who encounters this gotcha while wondering what's magically overriding their email callback on their user object.

Copy link
Contributor

Choose a reason for hiding this comment

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

@KelseyDH is there a pr to fix the devise overrides situation? If not, feel free to open so we can debate!

@KelseyDH
Copy link

KelseyDH commented Feb 22, 2018

Could there be any reason for wanting to preserve our calls to self.foo on this concern which initially was designed to target the user model?

If not, then this looks like a great a refactor overall. 👍

@zachfeldman zachfeldman merged commit e45539e into lynndylanhurley:master Feb 22, 2018
Evan-M added a commit to tmjfitch/devise_token_auth that referenced this pull request Mar 19, 2018
* Cleanup in ahead of refactor.

 - Rewrite terse code.
 - Remove superfluous implicit calls to self.
 - Move instance method out of `included do...` block.

* Refactor `#create_new_auth_token`.

 - Optionally accept extra attributes hash when calling `#create_token`.
 - Utilize token_extras hash for `#create_token` to DRY up `#create_new_auth_token`.
 - Synchronize the time used to set `expiry` and `updated_at`.
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