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

fix(registration and update): Ensure UID is updated alongside Email, and case-sensitivity is honored #71

Merged
merged 3 commits into from
Nov 15, 2014
Merged

fix(registration and update): Ensure UID is updated alongside Email, and case-sensitivity is honored #71

merged 3 commits into from
Nov 15, 2014

Conversation

booleanbetrayal
Copy link
Collaborator

@lynndylanhurley -

I missed a registrations_controller::create condition in #57 and fixed that. However, in additional testing I also discovered that uid was not being updated alongside email address, meaning from an authentication standpoint, the uid would never update to reflect the user's desired address change. I swore this worked at some point, but perhaps it broke recently as a result of being more resource friendly? I've added fixes and tests for both conditions, but it's arguable that uid should be abandoned entirely when using email based authentication (would require changes in sessions_controller as well any other place uid is explicitly referenced).

I've found another problem that arises from correctly updating uid though, as ng-token-auth is not context-aware of these updates and will preserve the old uid value in the auth_tokens hash. Meaning, after updating their email address and subsequently hitting a restricted HTTP call, the user will immediately be logged out. This is something that will probably have to happen in the response interceptor logic.

Let me know what your thoughts are. I can workaround it in client code as needed for now.

@booleanbetrayal booleanbetrayal changed the title fix(registration and update): Ensure UID is updated alongside Email, and Case Sensitivity is Honored fix(registration and update): Ensure UID is updated alongside Email, and case-sensitivity is honored Nov 10, 2014
@lynndylanhurley
Copy link
Owner

I get what you're saying about the uid value not being necessary for email, but removing it may cause other problems.

Currently, these are all the headers needed to identify a user:

  • uid
  • token
  • client
  • expiry

If the user is authenticated by both email and uid depending on the context (OAuth or email), then we need to add another header (provider or something) to let Rails know which attribute to search for users by.

Can we just add something like this to the User model concern?

before_save :sync_uid

def sync_uid
  uid = email if email.changed? and provider == 'email'
end

This would keep the user's uid in sync with their email, and I think it will keep the headers up-to-date as well.

@booleanbetrayal
Copy link
Collaborator Author

Sure thing. Let me tweak my PR a bit.

@booleanbetrayal
Copy link
Collaborator Author

There you go @lynndylanhurley !

I didn't retain the email_changed? check because the user concern explicitly overrides that for some reason. Maybe a comment explaining why would be useful there. Let me know if there are any other tweaks you think I should make.

@lynndylanhurley
Copy link
Owner

Awesome, thx! I'll review this ASAP!

@booleanbetrayal
Copy link
Collaborator Author

Hey @lynndylanhurley - Was wondering if you had any feedback for this PR or lynndylanhurley/ng-token-auth#64

@lynndylanhurley
Copy link
Owner

Hey @booleanbetrayal! Sorry for the delay. I haven't forgotten, I've just been super busy. I'll review + merge today for sure!

@booleanbetrayal
Copy link
Collaborator Author

No worries! Just let me know if you need any tweaks or anything. Thanks!

lynndylanhurley added a commit that referenced this pull request Nov 15, 2014
…l_registration

fix(registration and update): Ensure UID is updated alongside Email, and case-sensitivity is honored
@lynndylanhurley lynndylanhurley merged commit 415f406 into lynndylanhurley:master Nov 15, 2014
@lynndylanhurley
Copy link
Owner

Looks great! Thx @booleanbetrayal!!!

@lynndylanhurley
Copy link
Owner

Version 0.1.30.beta6 includes these fixes. I'll out the 0.1.30 final release on Monday - let me know if you find any more bugs before then!

@booleanbetrayal
Copy link
Collaborator Author

Sweet. Thanks @lynndylanhurley !

@booleanbetrayal booleanbetrayal deleted the fix_case_insensitive_email_registration branch November 17, 2014 14:46
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.

2 participants