Social Logins authentication through loopback-passport

删除回忆录丶 提交于 2019-12-01 12:35:28

According to the documentation provided here at -

https://www.npmjs.com/package/loopback-passport

You just have to install the loopback-passport npm module and add the following things to your project -

1) providers.json - This will define the configuration for third party auth providers you want to use like facebook, google plus etc. 2) In your server.js define passport default config as shown in the link like this -

var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();

// Create an instance of PassportConfigurator with the app instance 
var PassportConfigurator = require('loopback-passport').PassportConfigurator;
var passportConfigurator = new PassportConfigurator(app);

app.boot(__dirname);

...

// Enable http session 
app.use(loopback.session({ secret: 'keyboard cat' }));

// Load the provider configurations 
var config = {};
try {
  config = require('./providers.json');
} catch(err) {
  console.error('Please configure your passport strategy in `providers.json`.');
  console.error('Copy `providers.json.template` to `providers.json` and replace the clientID/clientSecret values with your own.');
  process.exit(1);
}

// Initialize passport 
passportConfigurator.init();

// Set up related models 
passportConfigurator.setupModels({
  userModel: app.models.user,
  userIdentityModel: app.models.userIdentity,
  userCredentialModel: app.models.userCredential
});

// Configure passport strategies for third party auth providers 
for(var s in config) {
  var c = config[s];
  c.session = c.session !== false;
  passportConfigurator.configureProvider(s, c);
}

After this you can check out the different client sdks provided to make requests for login or social authentication and use them for logging and registering users.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!