Non Cross-domain SSO

  • Last update:December 24, 2020
  • 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>

    Show Code

    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
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy