The redirect URI allows a server to act on behalf of a user. After a user login, a code variable is exchanged for a long lived token by the application server. More details about Oauth2 API can be found the Getting a Token page.

<a href="#" id="idnet-connect">
  Connect with Y8 Account to play
</a>

<script type="text/javascript">
window.idAsyncInit = function() {
    // When SDK is ready and when id.init event is triggered (all initialization processes are done i.e. ID.init called)
    // We register an event with jQuery
    // on click on the connect link it will open the Y8 Account authentication modal window
    ID.Event.subscribe('id.init', function(){
        $('#idnet-connect').on('click', function(){
            ID.register();
        });
    });

    // init the ID JS SDK
    ID.init({
        appId: 'YOUR_APP_ID', // App ID from the app dashboard
        status: true, // Force update the Y8 Account login status
        responseType: 'code', // 'token' by default
        redirectUri: 'https://mysite.com/callback' // override the redirect_uri
    });
};

(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://cdn.y8.com/api/sdk.js" : "http://cdn.y8.com/api/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'id-jssdk'));
</script>

Initialization parameters

The default status setting of false will improve page load times. It will check for cached data before calling the login API.

By setting status to true, the SDK will refresh the user authentication information instead of retreiving previously loaded data.

Capuring the Oauth response code

PHP example
Nodejs example