簡體   English   中英

使用Janrain和Ruby on Rails訪問當前用戶信息

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

我正在使用Janrain在Ruby on Rails應用程序中處理用戶會話。 它似乎正在運行,但是,我不知道如何判斷用戶是否已登錄或訪問當前用戶的信息。 用戶登錄后,是否創建了會話變量?

假設您指的是Janrain社交登錄(Engage),則當用戶通過社交提供商進行身份驗證后,小部件將獲得有效期為60分鍾的Janrain OAuth令牌。 您可以使用該令牌通過以下API端點檢索用戶的個人資料數據:(https:// {your-engage-domain.com} / api / v2 / auth_info)。

Janrain Social Login不維護任何與狀態相關的會話數據。 它只是簡化了身份驗證,並規范了從多個身份驗證提供程序中檢索用戶配置文件數據的過程。 一旦成功的身份驗證事件發生,則取決於您的服務器來驗證身份驗證令牌,然后建立與授權會話相關的任何形式的工作。

大多數社交服務提供商返回的訪問令牌有效期為30-60天。

試試'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

更多詳細信息請參見以下示例: https : //github.com/hatem/janrain-engage-demo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM