node oauth2验证

In my last articles, we looked at the implementation of the passport-local authentication strategy. We also looked at the various requirements to get started with the login form.

在上一篇文章中,我们介绍了护照本地身份验证策略的实现。 我们还研究了登录表单入门的各种要求。

Here are the previous articles,

这是以前的文章,

  • Passport local strategy section 1 | Node.js

    护照本地策略第1部分| Node.js

  • Passport local strategy section 2 | Node.js

    护照本地策略第2部分| Node.js

  • Passport local strategy section 3 | Node.js

    护照本地策略第3部分| Node.js

In this article, we will look at another form of authentication called the OAuth authentication which involves sign in or signup using social media.

在本文中,我们将介绍另一种身份验证形式,称为OAuth身份验证,它涉及使用社交媒体登录或注册

Don't worry that much about the big term OAuth... you'll get familiar with them as you work with Node.js more often.

不用担心OAuth这个大术语...随着您更频繁地使用Node.js,您会熟悉它们。

My goal here is to make it simpler for understanding and implementation.

我的目标是使其更易于理解和实施。

These codes are just to help you get started. So you can edit them at any time to confirm your desires.

这些代码仅是为了帮助您入门。 因此,您可以随时编辑它们以确认您的需求。

Note: You should have a basic understanding of Node.js, Express, MongoDB database and HTML.

注意:您应该对Node.js,Express,MongoDB数据库和HTML有基本的了解。

In this first section, we will set up our Express app with some routes and our HTML form.

在第一部分中,我们将使用一些路线和HTML表单来设置Express应用。

In the second section, we'll finally set up the authentication strategy it's self on Facebook developers platform and tests our code.

在第二部分中,我们最终将在Facebook开发人员平台上自行设置身份验证策略,并测试我们的代码。

Cheers!!!

干杯!!!

Create a new folder for our project where all files will be stored.

为我们的项目创建一个新文件夹,其中将存储所有文件。

Setup your Express Server.

设置您的Express Server。

Require all necessary modules and dependencies.

需要所有必要的模块和依赖项。

Create a file app.js and type the following code,

创建一个文件app.js并输入以下代码,

/*  EXPRESS SETUP  */
const express = require('express');
const app = express();
app.get('/', (req, res) => res.sendFile('index.html', {root: __dirname
}));
const port = process.env.PORT || 8080;
app.listen(port, () => console.log('App listening on port ' + port));

The code above creates an express server with port 3000 and a route that will read our index.html file.

上面的代码创建了一个带有端口3000的快速服务器,该路由将读取我们的index.html文件。

Next, let's create our simple HTML file... (you can at styles as you wish later).

接下来,让我们创建简单HTML文件...(以后可以按需要设置样式)。

Create a file called index.html in your project folder and type the following HTML code.

在项目文件夹中创建一个名为index.html的文件,然后键入以下HTML代码。

<html>
<head>
<title>Node.js OAuth</title>
</head>
<body>
<center>
<a href=auth/facebook>Sign in with Facebook</a>
</center>
</body>
</html>

Now, let's install passport-facebook and start looking at what we need for our OAuth facebook authentication.

现在,让我们安装Passport-facebook并开始查看OAuth facebook身份验证所需的内容

To install passport module for facebook authentication, run the following command on the terminal.

要安装用于Facebook身份验证的通行证模块,请在终端上运行以下命令。

Let's then configure our strategy and set up routes for success and failure authentication.

然后,让我们配置策略并设置成功和失败身份验证的路由。

Open the app.js file and add the following code below,

打开app.js文件,并在下面添加以下代码,

/*  CONFIGURATION  */
const passport = require('passport');
app.use(passport.initialize());
app.use(passport.session());
//success route
app.get('/success', (req, res) => res.send("You have successfully logged in"));
//error route
app.get('/error', (req, res) => res.send("error logging in"));
passport.serializeUser(function(user, cb) {cb(null, user);
});
passport.deserializeUser(function(obj, cb) {cb(null, obj);
});

The code above configures the module and sets up the error and success route.

上面的代码配置模块并设置错误和成功路线。

The success route function runs when authentication is successful while the error route runs when there's an error.

成功路由功能在身份验证成功时运行,而错误路由在出现错误时运行。

So if the user successfully logs in with his or her Facebook account, the web page will display ''you have successfully logged in''

因此,如果用户成功使用他或她的Facebook帐户登录,则网页将显示“您已成功登录”

And that's it guys for the first section of this tutorial...

这就是本教程第一部分的内容...

You can also visit the official website of passport to learn more @ http://www.passportjs.org/

您也可以访问护照的官方网站,以了解更多信息@ http://www.passportjs.org/

Read next: How to setup and use passport OAuth Facebook Authentication (Section 1) | Node.js

阅读下一篇: 如何设置和使用护照OAuth Facebook身份验证(第1节)| Node.js

Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question.

感谢您与我编码! 下次见。 随意发表评论或问题。

翻译自: https://www.includehelp.com/node-js/how-to-setup-and-use-passport-oauth-facebook-authentication-section-1-node-js.aspx

node oauth2验证

node oauth2验证_如何设置和使用护照OAuth Facebook身份验证(第1部分)| Node.js相关推荐

  1. node oauth2验证_如何设置和使用护照OAuth Facebook身份验证(第2部分)| Node.js

    node oauth2验证 In my last article (How to set up and use passport OAuth Facebook Authentication (Sect ...

  2. firebase登录验证_如何使用Firebase通过三步向身份验证本机添加身份验证

    firebase登录验证 Authentication allows us to secure our apps, or limit access for non-user members. Auth ...

  3. Springboot token令牌验证解决方案 在SpringBoot实现基于Token的用户身份验证

    Springboot token令牌验证解决方案 在SpringBoot实现基于Token的用户身份验证 参考文章: (1)Springboot token令牌验证解决方案 在SpringBoot实现 ...

  4. Facebook身份验证如何有效通过

    进行Facebook运营时最怕出现的就是验证,那Facebook身份验证如何才能有效的通过呢? Facebook运营时会碰到哪些问题? 账号被封,那Facebook就需要你提交相应的身份信息进行验证 ...

  5. HTTP 请求未经客户端身份验证方案“Anonymous”授权。从服务器收到的身份验证标头为“Basic realm=xxxxx”

     asp.net调用java的Web service(Web服务),需要用户及密码认证,弹出IE的登录窗口. 出现如下错误:HTTP 请求未经客户端身份验证方案"Anonymous&qu ...

  6. azure云数据库_在Azure SQL数据库中配置多重身份验证

    azure云数据库 介绍 (Introduction) The new SSMS 17.2 allows users to authenticate using Active Directory wi ...

  7. 谷歌身份验证器验证码不对怎么回事_暴雪战网游戏手机安全令,身份验证器的使用方法...

    对于没有绑定安全令的玩家,国际服客服明确表示只会帮助一次找回被盗账号,意思就是说,如果在没有绑定安全令的情况下,再次账号被盗,客服将不会受理,至于国服没有绑定安全令的情况下,对于再次账号被盗是否提供账 ...

  8. twilio无法验证手机_使用PHP和Twilio进行多因素身份验证

    twilio无法验证手机 There are various approaches used to confirm people are in fact who they say they: refe ...

  9. mysql windows身份验证_SQL Server 2005 怎么就不能用Windows身份验证方式登录呢?

    SQL Server 2005 自从装到我的电脑上始终无法使用Windows身份验证的方式登录,由于使用用户名和密码登录还算顺畅,所以一直忽略了这 SQL Server 2005 自从装到我的电脑上始 ...

最新文章

  1. JavaScript中的+0与-0
  2. matlab矩阵方块网络着色imshow_matlab中用imshow()显示图像与图像矩阵的数据类型的关系...
  3. 虚拟机屏幕界面自适应调整
  4. Flink从入门到精通100篇(二十四)-对Flink SQL Client 源码做深度解析
  5. thinkphp验证是否登录并跳转
  6. P4585-[FJOI2015]火星商店问题【线段树,可持久化Trie】
  7. python重定向到socket_python套接字流重定向实例汇总
  8. list python 转tensor_Pytorch--Tensor, Numpy--Array,Python--List 相互之间的转换。
  9. (王道408考研操作系统)第二章进程管理-第一节5:线程概念和多线程模型
  10. XP去除开机登陆画面
  11. sybase 设置默认值_[转]SYBASE 数据库操作笔记
  12. mysql 主从宕机切换_mysql主从复制配置操作以及主从宕机切换演练
  13. ps 计算机 性能设置,Photoshop 中的性能首选项
  14. jQuery插件开发详解
  15. DFI Update的原理与实现
  16. 读《我喜欢生命本来的样子》记(三)
  17. java解析micaps_9210的Micaps第13类卫星云图数据
  18. AutodeskADN 微信公众号和我个人邮箱
  19. 拼多多商品发布规则|一度智信
  20. 深入浅出WPF——什么是XAML

热门文章

  1. c语言输入字符时控制符%c前加空格的原因解释
  2. contentprovider java_创建Contentprovider,
  3. python的多行语句可以使用反斜杠_python 为什么不用分号作终止符?
  4. java怎么接收前端请求_前端json post 请求 后端怎么接收
  5. matlab meshgrid函数_matlab入门(三)图像可视化
  6. 数值分析方程求根实验matlab,数值分析实验之非线性方程求根(MATLAB实现)
  7. go反射实战之数组的查找Find过滤Filter函数实现
  8. 18-数据持久化-Data Volume
  9. Problem E: 建立链表(线性表)
  10. 冒泡排序算法(C#)