Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Login issue #1535

Closed
akash65 opened this issue Oct 20, 2018 · 8 comments
Closed

Login issue #1535

akash65 opened this issue Oct 20, 2018 · 8 comments
Labels
wontfix indicates an issue/pull request will not be worked on

Comments

@akash65
Copy link

akash65 commented Oct 20, 2018

Expected behavior:

When I try to login with credentials hradmin and test as username and password to login

Actual behavior:

But login credentials not working and it shows invalid username or password and I'm using couchdb 2.2

Steps to reproduce:

Screenshots (if applicable):

OS and Browser:
Chrome lastest and windows 10

@MatthewDorner
Copy link
Contributor

sorry things are not working well. Can you try this script and give a screenshot of the output? This one works for me with the CouchDB 2.2 I got from here: https://github.com/apache/couchdb-docker, though I'm still figuring out the details.

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $SECUREHOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_single_node","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'
else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

Even if this works and you can login you will probably have issues with Administration -> Users due to the problems described here #953. It's easier to use CouchDB 1.7.1 if you can.

@akash65
Copy link
Author

akash65 commented Oct 22, 2018

Hello,

  • I have tried with the above code inside clone folder "script/initcouch2.sh"
  • i have attached screenshots that i'm getting for login problem in couchdb 2.2
  • It says "unauthorized and username or paswword is incorrect

screenshot 176
screenshot 177

@MatthewDorner
Copy link
Contributor

Did you already set a CouchDB admin username and password? I think the script should work whether you did or not, but if you did set one, it must be username: 'couchadmin' password: 'test'

@akash65
Copy link
Author

akash65 commented Oct 22, 2018

Yeah i tried the command inside cloned folder "../script/initcouch2.sh couchadmin test" while running these command username or password is incorrect
screenshot 178

@LowBP
Copy link

LowBP commented Nov 16, 2018

@akash65 You should add "node_count":"3" to

   curl -X POST $HOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_cluster","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'

@aalmangour
Copy link

sorry things are not working well. Can you try this script and give a screenshot of the output? This one works for me with the CouchDB 2.2 I got from here: https://github.com/apache/couchdb-docker, though I'm still figuring out the details.

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $SECUREHOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_single_node","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'
else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

Even if this works and you can login you will probably have issues with Administration -> Users due to the problems described here #953. It's easier to use CouchDB 1.7.1 if you can.

I tried this script, still I cannot login

@LowBP
Copy link

LowBP commented Dec 22, 2018

@aalmangour please send me the output of your script?
Result of your script
screenshot 20

please try this script

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $HOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_cluster","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984, "node_count":"3"}'
    else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

The expected result

screenshot 21

@stale
Copy link

stale bot commented Aug 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix indicates an issue/pull request will not be worked on label Aug 7, 2019
@stale stale bot closed this as completed Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix indicates an issue/pull request will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants