【发布时间】:2016-10-13 14:35:05
【问题描述】:
如何在我的本地 postgresql 数据库中存储通过 Janrain 捕获身份验证进入 Janrain 数据库的注册表单的值。我的应用程序在 RoR 中。
【问题讨论】:
标签: ruby-on-rails ruby postgresql janrain
如何在我的本地 postgresql 数据库中存储通过 Janrain 捕获身份验证进入 Janrain 数据库的注册表单的值。我的应用程序在 RoR 中。
【问题讨论】:
标签: ruby-on-rails ruby postgresql janrain
首先,您不需要将注册表单数据存储在自己的数据库中。这在使用 Janrain 注册时是多余的。
一旦用户通过身份验证并且 Janrain OAuth 令牌已发送到注册小部件,您就可以使用该令牌调用实体端点:
https://SOME_APP_NAME.janraincapture.com/entity?access_token=someaccesstoken
这将以 json 格式返回经过身份验证的用户的个人资料数据。您可以使用此处记录的 attributes 参数过滤掉字段:https://docs.janrain.com/api/registration/entity/
https://SOME_APP_NAME.janraincapture.com/entity?access_token=someaccesstoken&attributes='["uuid","familyName","givenName"]'
您可能应该绑定到 Janrain Registrations Javascript 事件处理程序:“onCaptureCreateSession”,它在触发时将包含访问令牌。然后,您可以将该令牌发送到您的服务器,在那里它可以进行实体 api 调用,然后将任何相关数据存储在您的服务器中(如果需要)。
janrain.events.onCaptureSessionCreated.addHandler(function(result) {
//make an ajax call to your server here with the token:
var token = result.accessToken
});
如果您必须在提交表单之前获取表单字段数据,您可以绑定到表单的 onSubmit 事件,并在提交之前从表单中检索字段数据。这应该可以使用纯 Javascript 或大多数主流库来实现。
这是一个可以帮助您入门的示例:
janrain.events.onCaptureRenderComplete.addHandler(function(result) {
if (result.renderingBuiltInScreen == false) {
//NOTE: screen names can be configuration dependent.
if(result.screen == "traditionalRegistration" || result.screen == "socialRegistration"){
//bind to rendered form here and do stuff
//form names and field names are configuration dependent.
}
}
}
【讨论】:
class UsersController < ApplicationController require 'rest_client' def index @results = @ab @url def getData response = RestClient::Resource.new(@url,{ :content_type => :json, "secret" => "myapikey" } end def retrieve_results @id = params[:id] @url = "https://myapp.janraincapture.com/entity?access_token=#{@id}" @ab = JSON.parse(getData) end