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

Email used as auth_key uses exact case #22

Closed
bgilreath opened this issue Mar 25, 2012 · 9 comments
Closed

Email used as auth_key uses exact case #22

bgilreath opened this issue Mar 25, 2012 · 9 comments

Comments

@bgilreath
Copy link

Omniauth Identity seems to make distinction between capitalization on comparison in the identity table. A valid user with an email stored as joe.smith@abcdomain.com will fail if the user enters into the login form: Joe.Smith@abcdomain.com.

Any workaround suggestions work for me...Rails 2 specific please.

@smohanty29
Copy link

You can do something like below in Identitity model by monkey-patching authenticate method..

class Identity < OmniAuth::Identity::Models::ActiveRecord
belongs_to :user

put whatever validations etc you want

case in-sensitive

def self.authenticate(email, password)
return nil if email.nil? or password.nil?
self.find_by_email_ci(email.strip).try(:authenticate, password)
# replace the above line with ar query for CI, in my case I have a generic AR finder that I use in multiple places
end
end

@eugeneotto
Copy link

Another option would be to set the locate_conditions option in your Omniauth config, shown at the bottom of the README: https://github.com/intridea/omniauth-identity

This is mine:

locate_conditions: lambda { |req| { model.auth_key => req['auth_key'].downcase }

Note that as of right now, the omniauth-identity gem on Rubygems does not support this feature. You can install the Github version of omniauth-identity by adding this line to your Gemfile:

gem 'omniauth-identity', git: 'https://github.com/intridea/omniauth-identity.git'

@buildbreakdo
Copy link

For the sake of clarity...

#config/initializers/omniauth.rb
 provider :identity, locate_conditions: lambda { |req| 
    { model.auth_key => req['auth_key'].downcase }
  }

As ujeezy noted above, the omniauth-identity gem on Rubygems does not support this feature, this is still true. Make sure your gemfile is as he stated:

#Gemfile
gem 'omniauth-identity', git: 'https://github.com/intridea/omniauth-identity.git'

@ericpeters0n
Copy link

@joshua-robinson @eugeneotto
fyi, during identity creation:

NoMethodError at /auth/identity/callback
undefined method `downcase' for nil:NilClass 

So it appears the documented solution to this is not reliable.

@peterept
Copy link

I'm seeing this to.

Is there a work-around for case insensitive email comparison?

@buildbreakdo
Copy link

If you want to be quick and dirty downcase client side.

@peterept
Copy link

Thanks Joshua. I've done it that way. Here is my code change in:

app/views/identities/new.html.erb:

<script language="javascript">
function validateform() {
var emailInput = $('form#register-form input[name="email"]');
emailInput.val(emailInput.val().toLowerCase());
return true;
}
</script>

<%= form_tag "/auth/identity/register", :id => 'register-form' do %>
...
  <div class="field">
    <%= label_tag :email %><br>
    <%= text_field_tag :email, @identity.try(:email) %>
  </div>
...
  <div class="actions"><%= submit_tag "Register", :onclick => "return validateform();" %></div>
<% end %>

@strouptl
Copy link

I just updated @joshua-robinson @eugeneotto's solution with the following condition to get around the registration error noted by @ericpeters0n.

:locate_conditions => lambda { |req| { model.auth_key => (req['auth_key'].present? ? req['auth_key'].downcase : req['auth_key']) } }

Still a bit hacky, but at least you don't have to worry about clients having javascript disabled. This is on the current version, too.

@pboling
Copy link
Member

pboling commented Feb 14, 2021

It is now case insensitive!

@pboling pboling closed this as completed Feb 14, 2021
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

No branches or pull requests

8 participants