Node.js

Search Knowledge Base by Keyword

Contents

Required Node.js version is 6. Required modules: https.

The library can be downloaded at https://passport.winkk.com/partner/example/eye_oauth.js

Note: example listed below requires additional Node.js modules.

var https=require('https');
var oauth = require('./eye_oauth.js');
var express = require('express');
var fs = require('fs');
var app = express();

var options = {
  key: fs.readFileSync('server-key.pem'),
  cert: fs.readFileSync('server-crt.pem'),
  ca: fs.readFileSync('ca-crt.pem'),
  rejectUnauthorized: false
};

var server=https.createServer(options, app);

app.use(express.static(__dirname + '/public'));

app.get('/redirect', function (req, res){
  // Application ID from the step 13
  var client_id = "5953a9af05a1462e9c66a123";

  // Secret key from the step 13
  var secret = "secret_word";

  oauth.init(client_id,secret,req.query.code);
  oauth.profile(function(err,profile){
    if (err){
      res.end("OAuth error: "+err);
      return;
    }
    res.writeHead(200,{
      'Content-Type': 'text/html'
    });
    res.write('Hello ' + profile['personal.first_name'] + ', user_id is ' + profile.id);

    if (typeof(profile['personal.avatar'])!='undefined'){
      var bin=Buffer.from(profile['personal.avatar'],'base64');
      fs.writeFileSync('./public/av.bin', bin);
      res.write("<img src='/av.bin' />");
    }
    res.end(JSON.stringify(profile));
  });
});

server.listen(4400, function(){
  console.log('Example app listening on port 4400!');
});
Was this article helpful?
How can we improve this article?

Leave a Reply

Your email address will not be published. Required fields are marked *