How can I view user's personal data with omniauth?

retrograde

I want to view a user's personal data with the gem Omniauth with Ruby on Rails. Right now, I can only view public data. I get an error email can't be blank because I can only access public data, rather than personal user data. All answers are appreciated. Here's the code for my application:

#identity.rb

class Identity < ActiveRecord::Base
 belongs_to :user
 validates_presence_of :uid, :provider
 validates_uniqueness_of :uid, :scope => :provider

 def self.find_for_oauth(auth)
   find_or_create_by(uid: auth.uid, provider: auth.provider)
 end

end

#user.rb


      def self.find_for_oauth(auth, signed_in_resource = nil)
identity = Identity.find_for_oauth(auth)
user = signed_in_resource ? signed_in_resource : identity.user
if user.nil?

  email = auth.info.email
  user = User.where(:email => email).first if email

  # Create the user if it's a new registration
  if user.nil?
    user = User.new(
      full_name: auth.info.name,
      username: 'User'+auth.uid,
      email: auth.info.email,
      password: auth.uid
    )
    user.skip_confirmation!
    user.save!
   end 
end


if identity.user != user
  identity.user = user
  identity.save!
end
user
 end

#omniauth_callbacks_controller.rb


     def self.provides_callback_for(provider)
class_eval %Q{
  def #{provider}
    @user = User.find_for_oauth(env["omniauth.auth"], current_user)

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication
      set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
    else
      session["devise.#{provider}_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
}
 end

[:github, :google_oauth2].each do |provider|
provides_callback_for provider
 end
JeffD23

You will need to request a specific scope on your GitHub omniauth configuration.

config/initializers/devise.rb

config.omniauth :github, 'YOUR_API_KEYS', scope: 'user'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

OAuth in ADFS: how can I get user's personal data

From Dev

How can I view or hide some data depending of user logged in or not?

From Dev

Saving user's Facebook data from omniauth

From Dev

How can I view the contents of Varnish's hash_data()?

From Dev

How can I add data from User's Facebook to Firebase

From Dev

Using Omniauth, how can I see the repositories of a user who logs in with Github?

From Dev

How do I get a logged in user's name through omniauth-google-apps?

From Java

How can I view a git log of just one user's commits?

From Dev

How can I access the current user's roles in Orchard from a view page?

From Dev

How can i create view using the SYSTEM_USER's permission path in query

From Dev

how can i put view's inside view's in titanium

From Dev

How can I access a model's data inside a new view file?

From Dev

how can i set data to text view in the broadcast receiver's onreceive method

From Dev

How can I save and restore the last Image View seen by the user?

From Dev

omniauth-facebook user model data types

From Dev

omniauth-facebook user model data types

From Dev

How can I view raw image data in sublime text

From Dev

How can i load and display database data in my view?

From Dev

How can I pass data from parent to child view?

From Dev

How can i post data from view to controller in laravel 5.0?

From Dev

How can I share data from a different controller in a laravel view?

From Dev

how can I return axios data to feed view?

From Dev

How can I display data from multiple models in one view?

From Dev

How can I left align the extra columns in an Xpages Data View

From Dev

Swift: How can I bind data to a view in a loop?

From Dev

How can I view my Instagram backup data in a friendly way?

From Dev

How can I view older Google API quota data?

From Dev

When presenting a popover view, how can I let the user select cell in parent collection view?

From Dev

How can I restrict access to sensitive columns in Apache Drill view based on user permissions in another view?

Related Related

  1. 1

    OAuth in ADFS: how can I get user's personal data

  2. 2

    How can I view or hide some data depending of user logged in or not?

  3. 3

    Saving user's Facebook data from omniauth

  4. 4

    How can I view the contents of Varnish's hash_data()?

  5. 5

    How can I add data from User's Facebook to Firebase

  6. 6

    Using Omniauth, how can I see the repositories of a user who logs in with Github?

  7. 7

    How do I get a logged in user's name through omniauth-google-apps?

  8. 8

    How can I view a git log of just one user's commits?

  9. 9

    How can I access the current user's roles in Orchard from a view page?

  10. 10

    How can i create view using the SYSTEM_USER's permission path in query

  11. 11

    how can i put view's inside view's in titanium

  12. 12

    How can I access a model's data inside a new view file?

  13. 13

    how can i set data to text view in the broadcast receiver's onreceive method

  14. 14

    How can I save and restore the last Image View seen by the user?

  15. 15

    omniauth-facebook user model data types

  16. 16

    omniauth-facebook user model data types

  17. 17

    How can I view raw image data in sublime text

  18. 18

    How can i load and display database data in my view?

  19. 19

    How can I pass data from parent to child view?

  20. 20

    How can i post data from view to controller in laravel 5.0?

  21. 21

    How can I share data from a different controller in a laravel view?

  22. 22

    how can I return axios data to feed view?

  23. 23

    How can I display data from multiple models in one view?

  24. 24

    How can I left align the extra columns in an Xpages Data View

  25. 25

    Swift: How can I bind data to a view in a loop?

  26. 26

    How can I view my Instagram backup data in a friendly way?

  27. 27

    How can I view older Google API quota data?

  28. 28

    When presenting a popover view, how can I let the user select cell in parent collection view?

  29. 29

    How can I restrict access to sensitive columns in Apache Drill view based on user permissions in another view?

HotTag

Archive