Working Example

Below is the easiest example of how to interact with the JS interface. The client’s browser can directly receive data from id.net using a callback function.

If a backend server needs to act on behalf of a user, see the using a redirect URI page. Otherwise, see the auth functions page for more details about getting users logged in.

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<a href="#" id="idnet-login">Login</a>
<a href="#" id="idnet-register">Register</a>
<script type="text/javascript">
    window.idAsyncInit = function() {
        // use an id.net event to wait until after init
        ID.Event.subscribe('id.init', function(){
            // use jquery to call methods on clicks
            $('#idnet-login').click(function(){
                ID.login(idCallback);
            });
            $('#idnet-register').click(function(){
                ID.register(idCallback);
            });
        });
        // using an optional callback to capture data on the client
        var idCallback = function(response){
            if (response) { // That means that the server processed the response
                console.log(response);
                console.log(response.authResponse.details);
            }
        }
        // init the JS interface
        ID.init({
            appId : 'YOUR APP ID'
        });
    };
    
    // load the idnet js interface
    (function(d, s, id){
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement(s); js.id = id;
        js.src =  document.location.protocol == 'https:' ? "https://scdn.id.net/api/sdk.js" : "http://cdn.id.net/api/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'id-jssdk'));
</script>
</body>
</html>