【问题标题】:How do you add your own Oauth2 Passport strategy to a FeathersJS app?如何将自己的 Oauth2 Passport 策略添加到 FeathersJS 应用程序?
【发布时间】:2018-07-27 15:50:49
【问题描述】:

对于可能是一个明显的问题/答案,请提前道歉,但我一直在搜索文档但找不到它。

我知道 FeathersJS 有 Facebook/Twitter/Github 的插入式策略——我在文档中看到了这些策略。而且我知道您可以执行各种自定义授权策略。我要做的就是通过一个还没有预打包策略的 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

谁有一个可行的例子?

【问题讨论】:

    标签: feathersjs feathers-authentication


    【解决方案1】:

    该错误意味着您没有通过 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"
    }));
    

    【讨论】:

    • 谢谢!我想我在尝试设置策略上的所有 URL 和客户端信息时感到困惑,而不是 oauth2 配置。
    猜你喜欢
    • 2023-03-25
    • 2021-01-03
    • 1970-01-01
    • 2013-02-23
    • 2018-08-23
    • 2015-12-28
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多