-
Notifications
You must be signed in to change notification settings - Fork 229
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
Hotfix twitter login #6
base: master
Are you sure you want to change the base?
Conversation
I think it might make sense to not require email, but I need to think this through. @athix what do you think? |
Personally I think email should always be required by default, as it's how you verify who someone is for the most part, and send them important messages like account resets. I would first investigate the documentation and specs to make sure they make sense before removing the not null constraint. |
Yeah, lets look into the Twitter docs and see what we can/should do. |
I should've needed unique index on username. The last commit is the correction. |
I'm still up in the air about how best for us to approach username and e-mail. @athix do you have any further thoughts? |
As far as I'm aware, twitter oauth shouldn't care about your application's usernames (user logs in via twitter and oauth returns your app the UID & meta on success, sorcery associates the UID with an auth record then logs the appropriate user in). I think there probably is a bug somewhere in here, but I think it's with the documentation or the twitter implementation rather than the user migration. I would look into the problem myself, but unfortunately i'm pretty tied up between work and school at the moment and don't know if I have the time. As @ebihara99999 pointed out, sorcery's test suites are pretty inconsistent at the moment, and I know for a fact that the external providers aren't being properly tested. (I broke linkedin and the suite didn't fail because it only tests twitter for oauth1 providers for example) The process I would follow is:
Sorcery is pretty flexible, in @ebihara99999's case, it might be a thing where they really do need the not-null constraint removed. In that case, I would recommend installing sorcery then removing the constraint from his application's migration, rather than changing sorcery's generator. EDIT: |
Thank you @athix for the explanation. So I think it is a documentation problem as @athix said. I will fix the external page in wiki and send a pull request. In addition to documentation, I'm wondering how user activation works when a screen_name is set to email. I think I need to check it.
About this I create a rails app to reproduce a bug in sorcery-presentation-app on the replicate-bug branch. I'm happy if it's easier to trace the bug. EDIT: |
Thinking about test inconsistencies, I need suggestion about where to go.
For now, I tested in 3 ways:
In the firs case, the results are "354 examples, 27 failures, 2 pending", and these errors in the 3 files:
The messages are like this:
The second case, the results are "354 examples, 138 failures, 214 passed, 2 pending" caused by The last case: No failure. Which case do you think the schema is expected to be? |
I'd say username is an optional field for most applications. If we could get it working without a not null constraint, I think that would be ideal. |
I agree. |
ba6b446
to
ff5c128
Compare
I fix the test inconsistency about username and email constraints on users table
If screen_name maps to username and the user model has the email attribute, then it saves an empty string to email. |
@athix I think this is good to go, do you agree? |
Hey guys, sorry for interrupting. I've been waiting for this change. Just noticed the first user can be created with email blank but not for the second one because of the unique constraint on email column. Take a look at this case.
This will fail as follow
|
@tetsuya Interesting. This seems like a tricky issue. The model validations need to include |
Seems like email should be set to |
I agree that it's not good to set Another plan to deal with this problem, seen in case of devise, is to prepare a method that sets a random unique value like But none of them, including my solution, are best. Setting null causes an error, and setting unique random email is confusing because which of record's email is valid, really able to use email to send notification. My solution is not best but less confusing: making sure which email is really valid and avoiding an error. |
Introducing a user to register email after callbacks seems a very good idea, but it's not role of sorcery... |
Yeah, here's a (admittedly bad, I still need to clean this up) example of using |
@athix But asking for email registration is very good idea, setting "" to email makes it realize. Of course, in the external documentation, need to write about asking for email after registration if email is "". |
I'm sorry I made mistake: |
@ebihara99999 let us know when you have a fix |
@Ch4s3 I will make a method that generates a random email, not making up which to implement email as Then I would like to adopt |
I could probably live with |
This reverts commit b28de94.
This modification is for an external service that doesn't offer email like twitter.
- `"#{provider}-#{uid}@example.com"` breaks backward compatibility because in wiki it says `create_from_provider(provider)`: it doesn't pass uid. - `@example.com` makes it easy to check which email is valid or not
25ee480
to
6f7d553
Compare
I'd appreciate it if someone could give suggestion. One test case failed, but it isn't replicated on my local computer. And it doesn't seem to be relevant to what I changed. |
@ebihara99999 I'll try to take a look in the next day or so. |
@ebihara99999 You can use Personally, I'm against generating fake emails to satisfy the |
@ebihara99999 I think this still isn't quite ready for being merged, and unfortunately have run low on time to spend working on Sorcery. I'll probably leave this for a later release, but if you want to jump on IM or a video call to discuss this I could set aside some time to help with the issue. |
@athix It's OK to step this onto a later release. I don't have time to spend on this issue, either. Need time to catch up this issue... |
@ebihara99999 is this still an issue with the codebase, or can this be fixed with a documentation update? For the v1 update I plan on refreshing all of the documentation to be current with Rails 6 and other current best practices. |
@athix It's the issue of both codebase and documentation. As for codebase, it's needed to implement a feature to set unique value into email column in '#create_from_provider About documentation, uid must be passed to ref: #6 (comment) |
Looking at the See: Line 19 and Line 35 of the omniauth-twitter implementation.
|
This is moved from NoamB/sorcery pull request Hotfix twitter login #802. I copy the same request here for readability. If it's not easy to read, leave a comment to delete it.
Thank you for reading, looking forward to a comment.
About the bug
I found a bug with Twitter login with external module reported at the issue #800
How to fix
I tried to fix it by myself, then I add username property to and remove not null constraint of email from users in
lib/generators/sorcery/templates/migration/core.rb
.Username is needed when you login with Twitter, but email isn't needed.
Without username property, it raises error(mentioned in issue #800).
Thinking about email, not null constraint in a database layer raises an error
at
user.sorcery_adapter.save(:validate => false)
in#create_from_provider
inlib/sorcery/model/submodules/external.rb
.The error is:
Using #save with validate option, expected that a validation of email is ignored. The validation should be imposed only in model.
I wonder why tests don't fail, looking into specs.
In
spec/rails_app/db/migrate/core/20101224223620_create_users.rb
, different from the migration template mentioned above, defined are columns username and email without not null constraint.I think users defined in tests is expected, and I fix in this way.
How to test
I run all tests by
bundle exec rpsec
.I also confirmed expected migration template as follows:
I'm looking forward to a comment. Thank you for reading.