2012-09-02 54 views

回答

0

试“CURRENT_USER”变量,它适用于大多数的轨验证库,例如:

#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 

更多细节请参考下面这个例子:https://github.com/hatem/janrain-engage-demo

+0

问题是我没有会话中的user_id变量。你知道这通常设置在哪里吗?我看过你包含的链接,但我无法弄清楚。 –

+0

我不这么认为。如果您使用了身份验证gem/lib,则会话中必须有相关的变量或对象。请查看该文档,或粘贴所有相关代码或日志以进行调试。 –

1

假设你是指Janrain社会登录( Engage),一旦用户通过Social Provider进行身份验证,Widget将获得有效期为60分钟的Janrain OAuth令牌。您可以使用该令牌通过此API端点检索用户的配置文件数据:(https:// {your-engage-domain.com}/api/v2/auth_info)。

Janrain社交登录不维护任何登录状态相关的会话数据。它简化了身份验证过程并规范化了从多个身份验证提供程序检索用户配置文件数据的过程一旦成功的身份验证事件发生,您的服务器将验证身份验证令牌,然后建立任何形式的授权会话相关工作。

大多数社交提供者返回有效期为30-60天的令牌。