Janrain - 登录后重定向

时间:2016-02-04 12:02:57

标签: janrain

阅读Janrain文档我发现两个属性应该指示janrain在登录后重定向(http://developers.janrain.com/reference/javascript-api/registration-js-api/settings/#registration-flow):

  

redirectOnLogin - 将此项设置为启用或禁用。只有在将此值设置为启用时才会使用redirectUri。

     

redirectUri - 设置成功注册或登录后重定向的URL。

我尝试在janrain演示站点(http://demos.janrain.com/JanrainDemoSites/)上设置这两个属性:

janrain.settings.capture.redirectOnLogin = 'enabled';
janrain.settings.capture.redirectUri = 'http://demos.janrain.com/test';

但登录后我没有被重定向。 我错过了什么吗?

感谢。

1 个答案:

答案 0 :(得分:1)

使用Janrain注册窗口小部件,成功登录后重定向最可靠(在我看来最好)的方法是使用Javascript事件处理程序。

对于“标准”窗口小部件配置(没有SSO或任何其他集成),您将使用以下事件处理程序来执行重定向:

janrain.events.onCaptureLoginSuccess.addHandler(function(result) {
    if (window.console && window.console.log) console.log(result); 
    document.location = http://someserverandurlsomewhere.com        
});

janrain.events.onCaptureRegistrationSuccess.addHandler(function(result) {
    if (window.console && window.console.log) console.log(result); 
    document.location = http://someserverandurlsomewhere.com        
});

根据您的小部件的版本,您通常可以通过确保取消注释janrain-init.js文件中的以下行来将所有事件处理程序记录到浏览器控制台:

janrainUtilityFunctions().showEvents();

记录所有事件后,您可以查看成功登录或注册后发生的最终事件。您希望确保在完成所有必需的窗口小部件事件之前不重定向。例如,如果您正在使用SSO,那么通常会有一些额外的SSO事件在上述两个事件之后被触发。在SSO事件被触发之前重定向将阻止SSO会话正确设置。

希望这有帮助。