【问题标题】:How do I get User Profile Data from Janrain in Rails如何从 Rails 中的 Janrain 获取用户配置文件数据
【发布时间】:2016-10-13 14:35:05
【问题描述】:

如何在我的本地 postgresql 数据库中存储通过 Janrain 捕获身份验证进入 Janrain 数据库的注册表单的值。我的应用程序在 RoR 中。

【问题讨论】:

    标签: ruby-on-rails ruby postgresql janrain


    【解决方案1】:

    首先,您不需要将注册表单数据存储在自己的数据库中。这在使用 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.
        }
      }
    }

    【讨论】:

    • 当我在浏览器中点击 MY_APP_NAME.janraincapture.com/… 时,我可以看到 JSON 格式的数据,但是当我在控制器中做同样的事情时,我只会得到 url。我的控制器代码是: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
    • 哦,是的,我已经对你的答案投了赞成票,但现在我的声誉是
    • 嘿.. 需要您提供关于更新的更多建议.. 如果用户正在更新 janrain 中的配置文件数据..那么我也想更新我的本地数据库。那么从您的角度来看,我该如何更新本地数据库中的数据?
    • 如果其他人想知道,您可以使用上面演示的方法“拦截”任何注册表单。您只需要知道注册配置(又名“流程”)表单名称和显示它的屏幕名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    • 2020-07-13
    相关资源
    最近更新 更多