You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by carlosduclos <gi...@git.apache.org> on 2017/03/17 14:11:45 UTC

[GitHub] couchdb-nano issue #33: Can not get correct userctx

GitHub user carlosduclos opened an issue:

    https://github.com/apache/couchdb-nano/issues/33

    Can not get correct userctx

    [Original issue](https://github.com/dscape/nano/issues/342)
    
    __ceremcem__
    When I open the example.com/_session, it returns:
    ```javascript
    {"userCtx":{"roles":["_admin","_reader","_writer"],"name":"demeter"},"ok":true,"info":{"authentication_db":"_users","authentication_handlers":["delegated","cookie","default","local"],"authenticated":"cookie"}}
    ```
    But when I use the following code:
    ```shell
    err, body, headers <- nano.auth user.name, user.password
    console.log "err", err
    console.log "body: "
    console.log body
    console.log "headers..."
    console.log headers
    ```
    body returns
    ```javascript
    {"roles":[],"ok":true,"name":"demeter"}
    ```
    Which is not correct.
    
    *Edit*
    
    Following bash script also returns same response with nano:
    
    ```shell
    #!/bin/bash
    HOST=https://example.com
    
    curl -vX POST $HOST/_session \
        -H 'Content-Type:application/x-www-form-urlencoded' \
        -H 'Content-Type:application/json' \
        -d 'name=myuser&password=mypassword'
    ```
    So the problem might not be related with nano itself, it might be a setup issue.
    
    __ceremcem__
    However, following code gets the same correct userCtx with the browser:
    ```javascript
    require! \nano
    conn = nano cfg.url
    
    err, body, headers <- conn.auth cfg.user.name, cfg.user.password
    return console.log "err", err if err
    
    if headers and headers.\set-cookie
        cfg.cookie = headers.\set-cookie
    else
        return console.error "We got no cookie?", headers
    
    sconn = nano do
        url: cfg.url
        cookie: cfg.cookie
    
    err, session <- sconn.session
    return console.error "Err: ", err if err
    
    console.log 'Session is: ', session 
    ```

----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---