【问题标题】:Oauth2 github connection with feathersjs hosted on EC2Oauth2 github 与 EC2 上托管的 feathersjs 的连接
【发布时间】:2017-11-03 16:44:15
【问题描述】:

我在 github 上创建了一个带有 FeathersJS 后端的 Oauth 流。在本地主机上运行它时一切正常。目前,我正在 EC2 和 EC2 实例上测试到 AWS 的部署,我无法让流程正常工作。我得到了redirect_uri_error。

{
"error": "redirect_uri_mismatch",
"error_description": "The redirect_uri MUST match the registered callback URL for this application.",
"error_uri": "https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#redirect-uri-mismatch(2)"
}

我认为羽毛会根据配置文件中的参数自动创建重定向 uri。根据 uri 看起来像这样的文档:http(s)://hostname[:port]/auth/<provider>/callback。我正在使用以下设置在生产模式下运行该应用程序。我究竟做错了什么?

default.json:

{
  "host": "localhost",
  "port": 3030,
  "public": "../public/",
  "paginate": {
    "default": 10,
    "max": 50
  },
  "mongodb": "my_mongo_connection_string",
  "authentication": {
    "secret": "my_auth_secret",
    "strategies": [
      "jwt",
      "local"
    ],
    "path": "/authentication",
    "service": "users",
    "jwt": {
      "header": {
        "type": "access"
      },
      "audience": "https://example.com",
      "subject": "anonymous",
      "issuer": "feathers",
      "algorithm": "HS256",
      "expiresIn": "1d"
    },
    "local": {
      "entity": "user",
      "usernameField": "email",
      "passwordField": "password"
    },
    "github": {
      "clientID": "my_client_id",
      "clientSecret": "my_client_secret",
      "successRedirect": "/"
    },
    "cookie": {
      "enabled": true,
      "name": "feathers-jwt",
      "httpOnly": false,
      "secure": false
    }
  }
}

生产.json

{
  "host": "my-ec2-instance.compute.amazonaws.com",
  "port": "3030"
}

Github 配置

编辑:将 succesRedirect 更改为“/”

【问题讨论】:

  • 诚然,我以前从未使用过feathersjs,但只要查看该配置文件,github 属性successRedirect 就会出现在我身上。这可能是它用于redirect_uri 的东西吗?在这种情况下,您需要将其更新为 localhost 以外的其他内容。我还对您如何到达为 GitHub 中的回调配置的 /auth/github/callback 路径感到困惑。该路径不应该与您在successRedirect 中配置的路径匹配吗?
  • 嗨,马克,感谢您的回答。 successRedirect 是羽毛后端在一切顺利时将您重定向到的链接。我认为发生的事情是:您访问backend/auth/github。 Feathers 将您重定向到 Github。您批准访问。 Github 将您重定向到羽毛后端 (backend/auth/github/callback)。如果一切成功,feathers 会将您重定向到 successRedirect URI。所以我认为这无关紧要。但如果我错了,也许有人可以纠正我?
  • 您是否在 GitHub 上的应用程序配置中设置了错误消息并设置了相同的 URL?此外,生产应用程序预计将在端口 80 上运行。
  • 嗨达夫,感谢您的回答。它是相同的 URL。我尝试在端口 80 上使用 sudo 运行该应用程序(两者之间没有 nginx)。我尝试了指定 callbackURL 而没有在 default.json 中指定 callbackURL。它仍然不起作用。 github上的网址是一样的。就像在屏幕截图中一样。

标签: node.js amazon-web-services amazon-ec2 feathersjs feathers-authentication


【解决方案1】:

查看this feathersjs blog post 中的示例代码,您似乎需要在您的github 配置部分中添加一个callbackURL 参数,其值与您在GitHub 授权回调URL 中配置的值相同强>设置。

另外,我认为在 EC2 服务器上运行时,您需要将 github.successRedirect 设置修改为 http://my-ec2-instance.compute.amazonaws.com:3030/redirect,因为您配置的默认值 localhost 在 EC2 上运行时肯定不起作用.

【讨论】:

  • 嗨,马克,我也尝试添加 callbackURL (my-ec2-instance.compute.amazonaws.com:3030/auth/github/callback)。那没有用。另外,我目前正在重定向到“/”,这应该不是问题。感谢您的回答。
【解决方案2】:

好的,我找到了解决这个问题的方法。在生产模式下,羽毛应用程序仍然从 default.json 获取 URL 来构建回调 URL。因此,生产 URL 不仅应该填写在 production.json 中,还应该在 default.json 中输入相同的 URL。

【讨论】:

  • 要使用的配置由 NODE_ENV 变量决定。因此,在您的生产服务器上,设置 NODE_ENV=production 然后它将用 production.json 中的内容覆盖 default.json 中的内容
猜你喜欢
  • 2015-02-14
  • 2011-10-11
  • 2018-03-23
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
  • 1970-01-01
  • 2016-04-30
  • 1970-01-01
相关资源
最近更新 更多