[英]Implement Oauth 2.0 authentication mechanism using passport
我需要使用护照在我的node js应用中实现Oauth 2.0。但是,护照中的Oauth 2.0文档不包含架构定义和用户注册以及刷新令牌.node js中是否有带有护照的Restful API实现,类似于Laravel中的身份验证机制。
For REST API implementation with Node.js and passport.js oAuth 2.0, you can refer to this article. 对于Node.js的REST API的实现和passport.js的OAuth 2.0,你可以参考这个文章。 For more information, you can refer to this StackOverflow question. 有关更多信息,您可以参考此StackOverflow问题。
Use passport-oauth2 for this, 为此,请使用passport-oauth2,
npm install passport-oauth2 npm安装通行证-oauth2
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); }); } ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.