ruby-on-railsrubypostgresqljanrain

How do I get User Profile Data from Janrain in Rails


How can I store values of a registration form which are going to Janrain database through Janrain capture authentication in my local postgresql database. My application is in RoR.


Solution

  • Firstly, you shouldn't need to store registration form data in your own database. That would be redundant when using Janrain Registration.

    Once the user is authenticated and the Janrain OAuth token has been sent to the Registration widget you can use that token to call the entity endpoint:

    https://SOME_APP_NAME.janraincapture.com/entity?access_token=someaccesstoken
    

    This will return the authenticated user's profile data in json format. You can filter out fields using the attributes parameter as documented here: https://docs.janrain.com/api/registration/entity/

    https://SOME_APP_NAME.janraincapture.com/entity?access_token=someaccesstoken&attributes='["uuid","familyName","givenName"]'
    

    You should probably bind to the Janrain Registrations Javascript event handler: "onCaptureCreateSession" which when fired will contain the access token. You can then send that token to your server where it can make the entity api call and then store any relevant data in your server (if necessary).

    janrain.events.onCaptureSessionCreated.addHandler(function(result) {
      //make an ajax call to your server here with the token:
      var token = result.accessToken  
    });
    

    If you absolutely must get form field data before the form is submitted you could bind to the form's onSubmit event and simply retrieve the field data from the form before it is submitted. This should be achievable using plain Javascript or most mainstream libraries.

    Here's an example that should get you started:

    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.
        }
      }
    }