PostgresClientKit icon indicating copy to clipboard operation
PostgresClientKit copied to clipboard

Don't require caller to know the authentication type of the database when connecting

Open kkieffer opened this issue 1 year ago • 0 comments

When connecting to a database, the caller must know the type of authentication required and set that in the ConnectionConfiguration as the credential. In my fork, I added a "password" field to the ConnectionConfiguration. If that field is set, it overrides the credential field.

Example change in Connection.swift:

case let response as AuthenticationSASLResponse:
                
     let credential = configuration.password != nil ? .scramSHA256(password: configuration.password!) : configuration.credential
                
     guard case let .scramSHA256(password) = credential else {
           log(.warning, "SCRAM-SHA-256 credential required to authenticate")
            throw PostgresError.scramSHA256CredentialRequired
      }

Similar modifications can be made for md5 and plaintext response cases

kkieffer avatar Feb 01 '25 23:02 kkieffer