Oauth2 github 与 EC2 上托管的 feathersjs 的连接

Oauth2 github connection with feathersjs hosted on EC2

我已经在 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)"
}

我认为 feathers 会根据配置文件中的参数自动创建重定向 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
    }
  }
}

production.json

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

Github 配置

编辑:将 succesRedirect 更改为“/”

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

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

好的,我找到了解决这个问题的方法。在生产模式下,feathers 应用程序仍然使用 default.json 中的 URL 来构建回调 URL。因此,产生式URL不仅要填入production.json,同样的URL也要填入default.json。