Successfully!

Error!

Non Cross-domain SSO

  • Last update:  2020-12-24
  • I. Requirements

    1) The single sign-on interface of decision-making platform is suitable for cross-domain scenarios. The data structure returned is JSONP.

    2) If you are to get the Token through Android Native, or by calling a single sign-on interface in background using Java, and through a cross-domain interface, the data structure returned will be ({accesstoken:xxx}) rather than JSON. You have to remove the brackets to get the Token.

    3) Android Native is free from cross-domain issues. It allows the use of the normal login interface, and the data structure returned is JSONP.

    II. Samples

    1. Complete codes for non cross-domain single sign-on

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; " charset="UTF-8">
        <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
        <script type="text/javascript">
            function doSubmit() {
                var username = document.getElementById("username").value.trim();
                var password = document.getElementById("password").value.trim();
                if (username === "") {
                    window.alert("plese enter user name");
                    return false;
                }
                if (password === "") {
                    window.alert("plese enter password");
                    return false;
                }
                var url = "/webroot/decision/login";
          var data = {
            username: username,
            password: password,
            validity: -2,  //-2 means 'Stay logged in'
            origin: ""
          };
                jQuery.ajax({
            type: "POST",
                    url: url,
            dataType: "json",
            contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function (res) {
                        console.log(res);
                        if (res.errorCode) {
                            window.alert(res.errorMsg);
                        }else {
                var tokenCookie = "fine_auth_token=" + res.data.accessToken + ";path=/";
                if(res.data.validity === -2) {
                  var exdate = new Date();
                  exdate.setDate(exdate.getDate() + 14);
                  tokenCookie += ";expires=" + exdate.toGMTString();
                }
                document.cookie = tokenCookie;
                            window.location.href = res.data.url;
                        }
                    },
                    error: function () {
                        alert("timeout or other errors");
                    }
                });
            }
        </script>
    </head>
    <body>
    <p>Please Login in</p>
    <form id="login" name="login" method="POST" action="">
        <p>Username:<input id="username" type="text" name="username"/></p>
        <p>Passwrod:<input id="password" type="password" name="password"/></p>
        <input type="button" value="login" onClick="doSubmit()"/>
    </form>
    </body>
    </html>

    Save the codes above as a file and name it login.html

    login.html


    2. Preview

    Save the file named login.html to the directory under the path %FR_HOME%/webroot/

    Trigger the designer and type http://localhost:8075/webroot/login.html in the browser. The preview effect is shown as below:

    ezgif.com-gif-maker.gif

     

     

    Attachment List


    Theme: Decision-making Platform
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    Doc Feedback