postgres: Support scram-sha-256 authentication

As soon as I attempt a Client.connect I am having this error:

error: Uncaught Error: Unknown auth message code 10
        throw new Error('Unknown auth message code ${code}');
              ^
    at Connection.handleAuth (https://deno.land/x/postgres@v0.4.5/connection.ts:197:15)
    at Connection.startup (https://deno.land/x/postgres@v0.4.5/connection.ts:155:16)
    at async Client.connect (https://deno.land/x/postgres@v0.4.5/client.ts:14:5)

my client instantiation:

const client = new Client({
    user: 'postgres',
    password: 'postgres',
    database: 'test',
    hostname: 'localhost',
    port: 5432,
})

The permissions at launch deno run --no-check --unstable --allow-net --allow-env --allow-read app.ts --local

The service is obviously running and I can access the database through other means with the same credentials.

Edit: It would seems like i am able to connect to a remote database, but not the local one.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 15 (3 by maintainers)

Most upvoted comments

The error is related to supported encryption types. Newer versions of postgresql use scram-sha-256 for authentication. However, it appears that this driver only supports md5 encryption. To use new versions you will have to manually enter in a md5 hash for your postgres user’s password. How to generate md5 authentication for postgres: https://stackoverflow.com/a/58979721 Once you have the hash you can do:

ALTER USER username WITH ENCRYPTED PASSWORD 'md5yourmd5hashhere';

This driver should be updated to use the newer authentication as it is more secure.

Thanks to the effort of @snsinfu this is now supported, you can take it for a ride before the 0.9.0 release by importing from https://raw.githubusercontent.com/denodrivers/postgres/master/mod.ts

Closed in #267

Any updates on this? 😄