2

I'm using Janrain to handle user sessions in my Ruby on Rails app. It appears to be working, however, I don't know how to tell if a user is logged in or not or access the current user's information. After the user signs in, is there a session variable created?

Dan Palumbo
  • 105
  • 1
  • 7

2 Answers2

1

Assuming you are referring to Janrain Social Login(Engage), once the user authenticates through a Social Provider the widget gets a Janrain OAuth token that is valid for 60 minutes. You can use that token to retrieve the user's profile data through this API end point: (https://{your-engage-domain.com}/api/v2/auth_info).

Janrain Social Login does not maintain any log in state related session data. It simply facilitates authentication and normalizes the retrieval of user profile data from multiple authentication providers. Once a successful authentication event happens it is up to your server to validate the authentication token and then establish any form of authorization session related work.

Most Social Providers return access tokens that are valid for 30-60 days.

PBICS
  • 374
  • 2
  • 4
0

try 'current_user' variable, it works in most of the rails authentication libs, e.g.:

#in the erb file: 
<% current_user = session[:user_id] %>

# or in the rb file: 
class MusicController < ApplicationController
  before_filter :authenticate_user! # just like devise

  def index
    # same methods and api as devise.
    return if signed_in? and current_user.email
  end
end

# put this method in application_controller.rb
def current_user
  @current_user ||= User.find_by_id(session[:user_id])
end

more details refer to this example: https://github.com/hatem/janrain-engage-demo

Siwei
  • 19,858
  • 7
  • 75
  • 95
  • The problem is I don't have the user_id variable in the session. Do you know where this typically gets set? I've looked at that link you've included but I can't figure it out. – Dan Palumbo Sep 02 '12 at 15:46
  • I don't think so. If you have used the authentication gem/lib, there must be a related variable or object in session. please take a look at the document, or paste all the related code or logs for debug. – Siwei Sep 02 '12 at 21:37