代码之家  ›  专栏  ›  技术社区  ›  Jared

如何将自己的Oauth2 Passport策略添加到FeathersJS应用程序中?

  •  0
  • Jared  · 技术社区  · 7 年前

    对于一个明显的问题/答案,我提前表示歉意,但我一直在搜索文档,却找不到它。

    我知道FeathersJS在Facebook/Twitter/Github上有投放策略——我在文档中看到了这些策略。我知道你可以做各种定制授权策略。我所要做的就是通过Oauth2提供者对用户进行身份验证,而Oauth2提供者还没有预先打包的策略。我找不到这样的工作示例。

    更令人沮丧的是,当我尝试遵循示例/文档时,我会从feathersjs npm模块中得到错误,例如:

        <...>/node_modules/@feathersjs/authentication-oauth2/lib/index.js:96
          app.passport.use(name, new Strategy(oauth2Settings, verifier.verify.bind(verifier)));
                                 ^
    TypeError: Strategy is not a constructor
    

    有没有人有一个有效的例子?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Daff    7 年前

    该错误意味着您没有通过Passport oAuth2策略。您可以设置 general Passport oAuth2 adapter 非常类似于 example in the documentation :

    const oauth2 = require('@feathersjs/authentication-oauth2');
    const OAuth2Strategy = require('passport-oauth2').Strategy;
    
    app.configure(oauth2({
      name: 'custom',
      Strategy: 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"
    }));