简体   繁体   English

使用Janrain和Ruby on Rails访问当前用户信息

[英]Accessing current user information with Janrain and Ruby on Rails

I'm using Janrain to handle user sessions in my Ruby on Rails app. 我正在使用Janrain在Ruby on Rails应用程序中处理用户会话。 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? 用户登录后,是否创建了会话变量?

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. 假设您指的是Janrain社交登录(Engage),则当用户通过社交提供商进行身份验证后,小部件将获得有效期为60分钟的Janrain OAuth令牌。 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). 您可以使用该令牌通过以下API端点检索用户的个人资料数据:(https:// {your-engage-domain.com} / api / v2 / auth_info)。

Janrain Social Login does not maintain any log in state related session data. Janrain Social Login不维护任何与状态相关的会话数据。 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. 大多数社交服务提供商返回的访问令牌有效期为30-60天。

try 'current_user' variable, it works in most of the rails authentication libs, eg: 试试'current_user'变量,它在大多数的Rails身份验证库中都有效,例如:

#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 更多详细信息请参见以下示例: https : //github.com/hatem/janrain-engage-demo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM