Step 1. Redirecting user to id.net

To use id.net authorization, your application has to present user an id.net window, that will log user in (or create new account if user does not have one) and then ask him to give your application access to one of his identities. There are various ways to provide application login: iframe window, new window popup, SDK call etc, but we will consider the most simple one - plain redirect.

We will cover ID.net javascript SDK way. To read about it in detail, you can visit JavaScript page.

First and foremost, you have to integrate id.net javascript sdk into your page:

<script type="text/javascript">
  window.idAsyncInit = function() {
    // Triggered when id.net SDK has finished initialization
    ID.Event.subscribe('id.init', function(){
      // When user clicks on the link it will open the authentication modal
      jQuery('#idnet-connect').on('click', function(){
        ID.login();
      })
    );

    ID.init({
        appId         : 'YOUR_APP_ID',                              // App ID from the app dashboard
        status        : true,                                       // Check Id.net Login status
        responseType  : 'code',                                     // 'token' by default
        redirectUri   : 'https://mysite.com/auth/idnet/callback'    // default 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://scdn.id.net/api/sdk.js" : "http://cdn.id.net/api/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'id-jssdk'));
</script>

Step 2. Server side

// This is a simple node server to use id.net OAuth 2.0 authorization service
// Install dependencies to make this code work
// npm install request

var request = require('request');
var http = require('http');
var url = require('url');
var site = 'https://www.id.net';

http.createServer(function (req, response) {
  var queryData = url.parse(req.url, true).query;
  var pathname = url.parse(req.url).pathname;
  // You can customize this callback as you want
  if (pathname === '/auth/idnet/callback') {

    // check if there is a code
    if (queryData.code) {
      var exchange = {
        code: queryData.code,
        client_id: 'APP_ID', // replace by your APP_ID
        client_secret: 'APP_SECRET', // replace by your APP_SECRET
        grant_type: 'authorization_code'
      };
      // Exchange code for an access_token
      request.post(site + '/oauth/token', {form: exchange}, function(e,r, body){
        var obj = JSON.parse(body);
        console.log(obj);
        // You need to store this object in your database to reuse it and call API on behalf of the user
        var token = obj.access_token;
        options = {
          headers: {
            Authorization: 'Bearer ' + token
          }
        }
        // Request User information API with access_token
        request.get(site + '/api/v1/json/profile', options, function(e, r, body){
          var obj = JSON.parse(body);
          console.log(obj);
          response.end('Connected as ' + obj.nickname + ' / PID: ' + obj.pid);
        });

      });
    }
  }
}).listen(4000);