护照2
此分叉执行可选的回调函数, 用于通过客户端 ID 和 secret 每次在认证前直接访问 Oauth2 。 此函数称为 带有请求对象.
passport.use(new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
getClient: async function(req) {
// some possible async operations
// ...
return {
id: '#####',
secret: '#####'
}
},
callbackURL: "http://localhost:3000/auth/example/callback"
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ exampleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
====================================================================================
OAuth 2.0认证战略 护照。 。 。 .
本模块允许您在节点.js应用程序中使用 OAuth 2. 0 认证. 通过插入Passport,OAuth 2.0认证可以轻松和 毫无侵扰地融入任何支持 连接- 型式中间器件,包括 快递。 。 。 .
注意这一策略提供了通用的OAuth 2.0支持. 在许多情况下,a 可采用针对供应商的战略,以减少不必要的 配置,并包含任何特定提供者的突触。 见 列表 用于支助 供养者.
需要针对 OAuth 2. 0 提供者执行认证的开发者 鼓励尚未获得支持的单位对该战略进行分级。 狦 请选择打开源码 列表,以便其他人可以找到它.
广告
学习 OAuth 2. 0 - 作为API 安全专家开始
想象一下,如果你在OAuth有8500个满意的学生, 你的职业生涯会怎样
安装
$ npm install passport-oauth2
使用量
配置策略
OAuth 2.0 认证策略使用第三方认证用户
账户和OAuth 2.0 令牌。 供应商的 OAuth 2.0 端点以及
客户身份识别和秘密,指定为选项。 战略
需要一个 verify 接收访问符和配置文件的回调,
和电话 cb 提供用户.
passport.use(new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
clientID: EXAMPLE_CLIENT_ID,
clientSecret: EXAMPLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/example/callback"
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ exampleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
认证请求
使用 passport.authenticate(),指定 'oauth2' 战略
认证请求.
例如,作为路由中间软件在一个 快递 应用程序 :
app.get('/auth/example',
passport.authenticate('oauth2'));
app.get('/auth/example/callback',
passport.authenticate('oauth2', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
相关模块
捐款
测试
测试套房位于 test/ 目录。 所有的新特点都是
预计将有相应的测试案例。 确保完整的测试套件
通过执行:
$ make test
覆盖范围
所有新功能的开发预计将有测试覆盖. 补丁 英克瑞斯的测试覆盖率是愉快的接受的。 覆盖面报告可通过下列方式查阅: 执行 :
$ make test-cov
$ make view-cov
许可证
版权(c)2011-2016年Jared Hanson <http://jaredhanson.net/ (中文(简体) )> 翻译: