İsmail Altun
İsmail Altun

Reputation: 21

I am not able to do create database in CouchDB 3.x with Admin

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.

Upvotes: -1

Views: 5055

Answers (2)

terija
terija

Reputation: 11

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

Upvotes: 1

RamblinRose
RamblinRose

Reputation: 4953

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

Upvotes: 0

Related Questions