title: Devise Omniauth with google open-id access token information
body: <p>I'm new in rails and I'm trying to integrate omniauth and the login with google.
  Surfing on the web i found a way to do it, but i got this error:</p>
  
  <pre><code>undefined method `[]' for nil:NilClass
  
  app/models/user.rb:22:in `find_for_open_id'
  app/controllers/users/omniauth_callbacks_controller.rb:17:in `open_id'
  </code></pre>
  
  <p>I think that is because i don't access correctly the access token information.</p>
  
  <p>here is the code:</p>
  
  <p>Model users.rb</p>
  
  <pre><code>def self.find_for_open_id(access_token, signed_in_resource=nil)    
      data = access_token['user_info']
      if user = User.find_by_email(data["email"])
      user
      else # Create a user with a stub password.
        User.create!(:email =&gt; data["email"], :password =&gt; Devise.friendly_token[0,20])
      end
    end
  </code></pre>
  
  <p>omniauth_callbacks_controller.rb</p>
  
  <pre><code>def open_id
      # You need to implement the method below in your model
      @user = User.find_for_open_id(env["omniauth.auth"], current_user)
      if @user.persisted?
        flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind =&gt; "Google"
        sign_in_and_redirect @user, :event =&gt; :authentication
      else
        session["devise.open:id_data"] = env["openid.ext1"]
        redirect_to new_user_registration_url
      end
    end
  </code></pre>
  
  <p>devise.rb</p>
  
  <pre><code>config.omniauth :open_id, :store =&gt; OpenID::Store::Filesystem.new("/tmp"), :name =&gt; 'open_id', :identifier =&gt; 'https://www.google.com/accounts/o8/id'
  </code></pre>
  
  <p>I don't know what else i can show you.</p>
  
  <p>For me the problem is here:</p>
  
  <p>data = access_token['user_info']</p>
  
  <p>access_token['user_info'] returns null.</p>
  
  <p>Am I doing something wrong? Is there other way to access the 'user_info' and then the e-mail?</p>
  
  <p>Thanks in advance. Hope i'm clear.</p>