通过回送密码进行社交登录身份验证 [英] Social Logins authentication through loopback-passport

查看:76
本文介绍了通过回送密码进行社交登录身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始以loopback api为由.目前,我正在尝试通过社交登录为我的应用程序集成身份验证.我发现了三个页面,指出了如何做到这一点,但是它们都以不同的方式显示了这一点,并且不清楚: github -loopback-component-passport & npmjs-loopback-component-passport & github-loopback-component-passport-example .对于最新的流程,我有些困惑.谁能阐明如何最好地将社交登录与环回集成?另外,如何针对可能需要访问令牌的路由对其进行测试?这是该项目的 Github存储库.

I am starting to gain grounds with loopback api. Currently I am trying to integrate authentication through social login for my app. I have found three pages that indicate how to accommplish this but they all show this a bit differently and unclear: github-loopback-component-passport & npmjs-loopback-component-passport & github-loopback-component-passport-example. I am bit confused as to what is the most up to date process. Can anyone shed some light in how to best integrate social login with loopback? Also, how to test it for routes that may require access tokens? Here is the Github Repo of the project.

当前依赖项

"dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "lodash": "^3.10.1",
    "loopback": "^2.26.2",
    "loopback-boot": "^2.6.5",
    "loopback-component-explorer": "^2.1.0",
    "loopback-connector-mysql": "^2.2.0",
    "loopback-datasource-juggler": "^2.19.0",
    "loopback-stormpath": "0.0.1",
    "serve-favicon": "^2.0.1",
    "passport": "^0.3.2",
    "underscore": "^1.8.2"
  }

推荐答案

根据此处提供的文档-

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

您只需要安装loopback-passport npm模块并将以下内容添加到您的项目中-

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

1)provider.json-这将为您要使用的第三方身份验证提供程序定义配置,例如facebook,google plus等. 2)在您的server.js文件中,定义护照默认配置,如链接所示-

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);
}

此后,您可以检查提供的不同客户端SDK,以进行登录或社交身份验证请求,并将其用于登录和注册用户.

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.

这篇关于通过回送密码进行社交登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆