【问题标题】:how to connect postgres database with Auth0如何使用 Auth0 连接 postgres 数据库
【发布时间】:2015-06-07 03:53:57
【问题描述】:

当我用 Auth0 连接 heroku postgres 数据库时,我遇到了错误。

could not connect to postgres db { [error: no pg_hba.conf entry for host "XXXXXXXX", user "XXXXXX", database "XXXXXX", SSL off]
  name: 'error',
  length: 161,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '496',
  routine: 'ClientAuthentication' }
[error] 28000 - undefined

我正在使用 Auth0,所以请在下面找到带有 heroku 数据库详细信息和 URL 的 auth0 代码。

configuration.config_file = "postgres://username:password@host:port/DB_name"

function login (email, password, callback) {

  var conString = configuration.config_file;
  postgres(conString, function (err, client) {
    if (err) {
      console.log('could not connect to postgres db', err);
      return callback(err);
    }
  });
}

【问题讨论】:

  • 欢迎来到 Stackoverflow。如果您有任何错误消息,请发布。
  • 您是否授予了适当的权限以允许访问您的数据库? pg_hba.conf 文件是访问权限,似乎您的服务器的 IP 未在此处列出或没有适当的权限。
  • @yakiklein 你能告诉我当我们使用 auth0 访问 heroku 数据库时如何授予权限吗?
  • 看看我下面的回答。希望对您有所帮助。
  • @GauravGupta 你是如何解决这个问题的?

标签: ruby-on-rails ruby node.js heroku-postgres auth0


【解决方案1】:

尝试将 '?ssl=true' 添加到您的 conString。 Heroku 需要通过 SSL 进行远程连接。有关详细信息,请参阅https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js(在“远程连接”下)。

【讨论】:

    【解决方案2】:

    您在此处编写的代码在 Auth0(云端)中运行。这意味着您需要使用 Auth0 可以连接的主机名或 IP 地址。

    如果您使用像 DBSERVER01 这样的主机名或像 10.10.5.1 这样的 IP 地址,这些仅在您的网络中可用,并且 auth0 将无法访问它们。

    确保使用网络的公共 IP 地址(如 45.19.3.29)或面向公众的主机名(如 mydb01.mycompany.com)。

    【讨论】:

    • 如何使用 auth0 访问本地机器上的 heroku postgres 数据库?
    • 根据 Heroku 的这个文档:devcenter.heroku.com/articles/…,您不应该对数据库 URL 或 IP 进行硬编码。您应该通过heroku config:get DATABASE_URL -a your-app 获取它。但是,当使用 auth0 的数据库操作脚本时,这是有问题的,因为它们是沙盒的并且不允许网络访问。我还没有弄清楚——还有其他人想出解决方案吗?
    【解决方案3】:

    看看这个来自 ubuntu 网站的document。它解释了如何在本地安装 postgres 数据库。

    安装 postgres 后,您需要创建一个用户并对其进行适当的身份验证。

    【讨论】:

    • 谢谢,我想在本地使用heroku数据库和auth0。请看我的代码。
    • 这个答案没有解决 OP 正在使用 heroku 的事实。
    猜你喜欢
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多