使用护照实现Oauth 2.0认证机制

时间:2018-02-13 04:51:26

标签: node.js oauth passport.js

我需要使用passport在我的节点js应用程序中实现Oauth 2.0。但是护照中的Oauth 2.0文档不包含模式定义和用户注册以及刷新令牌。节点js中是否有任何Restful API实现,其中护照类似于认证机制在Laravel。

2 个答案:

答案 0 :(得分:1)

对于使用Node.js和passport.js oAuth 2.0的REST API实现,您可以参考this文章。有关详细信息,请参阅this StackOverflow question.

答案 1 :(得分:0)

使用passport-oauth2,

npm install passport-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);
    });
  }
));




有关详细信息,请参阅Here

相关问题