-1

Just installed couchdb 3.00 version in windows machine and configured as single node.

Defined admin in installation, even after installation. Restarted couchDB after definitions.

My admins appears in UI: enter image description here

But when i try to create db via shell script it responses:

enter image description here

I am absolutely sure that my passwords are correct.

I wonder if there is a bug or mistake i've made.

İsmail Altun
  • 21
  • 1
  • 5

2 Answers2

1

At starting by Couchdb 3 is mandatory using autenthication for PUT or DELETE operation. Invoke-WebRequest had -Authorization param for this purpose. But authentication is in clear format. I use PSCouchDB (https://pscouchdb.readthedocs.io/en/latest/auth.html) for used authentication in SecureString password object.

For example:

$password = "password" | ConvertTo-SecureString -AsPlainText -Force

Set-CouchDBSession -UserId admin -Password $password

Set-CouchDBSession -UserId admin    # prompt password

New-CouchDBDatabase -Database test
Rizwan Mehboob
  • 1,333
  • 17
  • 19
terija
  • 11
  • 1
0

The issue is not related to CouchDB, rather the allowed authentication methods with Invoke-WebRequest.

Though I cannot find any documentation that explicitly states URL credentials are not supported, I do find in the PowerShell documentation1 a list of authentication methods that are supported:

-Authentication

Specifies the explicit authentication type to use for the request. The default is None. Authentication cannot be used with UseDefaultCredentials.

Available Authentication Options:

None: This is the default option when Authentication isn't supplied; no explicit authentication is used.

Basic: Requires Credential. The credentials are sent in an RFC 7617 Basic Authentication header in the format of base64(user:password).

Bearer: Requires Token. Sends an RFC 6750 Authorization: Bearer header with the supplied token. This is an alias for OAuth

OAuth: Requires Token. Sends an RFC 6750 Authorization: Bearer header with the supplied token. This is an alias for Bearer

I interpret the above to mean the authentication method you are using is not supported.

Here's one example using Basic authentication, one of surely hundreds of ways to perform your task.

 # setup variables to form a HTTP Basic Authorization
 $uid = "<username>"
 $pwd = "<password>"
 # Convert the Basic credentials to bytes
 $atob = [System.Text.Encoding]::UTF8.GetBytes($uid +":" + $pwd)
 # To Base64 encoding
 $auth = "Basic " + [System.Convert]::ToBase64String($atob)
 # Create the database
 Invoke-WebRequest -Method PUT -Url http://127.0.0.1:5964/abc -Headers @{"Authorization"=$auth}

FWIW, cURL allows the ease of inline URL http authentication, but that may not be an option.

The above code borrows from this SO Q/A answer regarding Basic authentication.

1 PowerShell Documentation Version 7

RamblinRose
  • 4,883
  • 2
  • 21
  • 33
  • 1
    it worked ! I used to use powershell for modifying couchdb when the version was 2.3.1. As it pointed out [here](https://docs.couchdb.org/en/latest/intro/api.html) , i used url credential in powershell but seems like there is a difference in handling requests between cURL and powershell's invoke-WebRequest method – İsmail Altun Mar 16 '20 at 09:50