Search code examples
ruby-on-rails-3emaildeviseomniauthlinkedin-api

Omnoauth login using Linkedin not supply email in info hash


I am using omniauth with LinkedIn as a provider. LinkedIn doesn't supply an email in info hash, so i cannot provide an email when create the user based on the information I get back.

Two related questions:

1) How can I adjust devise so that there isn't a requirement for :email as a validation? It doesn't appear to be set under the User model.

2) I do want to get the email information, however, so want to have email information requested before creating the User. How can I redirect to a page/wizard asking for email information and then come back to finish the user registration?


Solution

  • Take a look at the railscasts about omniauth: http://railscasts.com/episodes?utf8=%E2%9C%93&search=omniauth

    The idea is the following:

    • Create a new user from the omniauth info
    • try to save the user
    • since the email is not present it won't validate
    • store the omniauth data in the session and redirect_to new_user_registration_url
    • create your own registration controller that inheritates from the devise one
    • override the build_resource(*args) method, and if the omniauth data is present, use it to create the resource (User in your case)

    That way, after trying to login with linkedin, the user will be redirected to a form where he will be able to enter his email.

    It's all explained in the railscast ;)