Application(Client) Sample code (HTML)

From ESS-WIKI
Revision as of 07:25, 16 January 2017 by Dylan.chang (talk | contribs) (Created page with "<!--<br/>  ~ Copyright 2016 Red Hat, Inc. and/or its affiliates<br/>  ~ and other contributors as indicated by the @author tags.<br/>  ~<br/>  ~ Licensed u...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


<html>
<head>
    <title>SSO Test</title>
    <script src="https://openidserver.redirectme.net:8443/auth/js/keycloak.js"></script>
    <script>
        var keycloak = Keycloak('OpenID.json');
        function reloadData(){
            keycloak.updateToken(10)
                    .success(frmLogin_getOpenIDCallback)
                    .error(function() {
                        alert('Failed to load data.  User is logged out');
                    });
        }
        
        function LoginSSO()
        {
            keycloak.init({ onLoad: 'login-required' })
                .success(reloadData)
                .error(function(errorData) {
                    document.getElementById('customers').innerHTML = '<b>Failed to load data. Error: ' + JSON.stringify(errorData) + '</b>';
                    alert(JSON.stringify(errorData));
                });
        }    
        function frmLogin_getOpenIDCallback()
        {
            console.log(keycloak);
            console.log(keycloak.token);
        }
        if (window.location.hash != "")
        {
            LoginSSO();
        }
    </script>
</head>
<body>
<br><br>
<button onclick="LoginSSO()">SSO login</button>
</body>
</html>