0

i am new to ruby environment.

In my ruby app, i am authenticating the user using omniauth and i am able to save the facebook token for the logged in user and the problem is i want to pass this token information as parameter to koala which resides in some other controller?

How to do it? Kindly help.

MY OMNIAUTH CONTROLLER:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
     @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
     ...
  end

User.rb

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  token = access_token.credentials.token //i want to pass this to invite controller

  cookies[:myKey] = token

  if user = self.where(:email => data.email).first
    if(!user.facebook_id)
      if(user.sign_in_count != 0)
        user.facebook_id = data.id 
        user.token = access_token
        user.save
      else
        user.destroy
        user = User.new(:name=>(data.name).split(" ")[0], :email => data.email, :password => Devise.friendly_token[0,20], :provider => "facebook", :facebook_id => data.id)
        user.skip_confirmation!
        user.save!
      end
    end
  user
  else # Create a user with a stub password. 
  user = User.new(:name=>(data.name).split(" ")[0], :email => data.email, :password => Devise.friendly_token[0,20], :provider => "facebook", :facebook_id => data.id)
  user.skip_confirmation!
  user.save!
  user
  end

end

MY INVITE CONTROLLER (where i am trying to fetch facebook user data using koala gem)

class InviteController < ApplicationController

def invite
fb ||= Koala::Facebook::API.new(cookies[:myKey])
     @friends = fb.get_connections("me", "friends")
  render json: @friends
 end
end

1 Answers1

0

Now i am storing the token in database. It's working fine now! Thanks all.