miholzi
miholzi

Reputation: 994

cochdb permissions roles always "not authorized"

I try to make a user / role authentication (session based) with CouchDB but as soon as I enter a role at a database all users and roles are can access the database -> the are not authorized.

Get the session:

POST http://myhost:1234/_session

It returns (the userCtx object):

{
    "ok": true,
    "name": "some_user_name",
    "roles": [
        "developers"
    ]
}

Then I added the roles to the database:

PUT http://myhost:1234/database/_security

{
    "admins": {
        "names": [],
        "roles": []
    },
    "members": {
        "names": [],
        "roles": [
            "developers"
        ]
    }
}

and it returns {"ok":true} and I can see the permissions also in fauxton.

When I now try to access the database with

GET http://myhost:1234/database/_all_docs

it returns:

{
    "error": "unauthorized",
    "reason": "You are not authorized to access this db."
}

Upvotes: 2

Views: 3472

Answers (2)

Saugat Bhattarai
Saugat Bhattarai

Reputation: 2750

If you are using Postman, Add Following key-value in Headers

"Content-Type": "application/json",
  Accept: "application/json",
  Authorization: "Basic " + btoa("YOUR_ADMIN_USER:YOUR_PASSWORD")

Upvotes: 2

miholzi
miholzi

Reputation: 994

ahhh I found the mistake, I was doing the tests with postman and there I did not recognized that the credentials was not send with the requests :-(

Upvotes: 0

Related Questions