Get current logged in user name


#1

Is it possible to get current logged in user name using couchbase lite REST API?


#2

can you elaborate your requirement ? If a user logs into your app, wouldn’t you know the currently logged in user name?


#3

I use OpenId Connect to authorization with “register”:true. Sync gateway creates username using “issuer” and userId. For example localhost%3APORT%2Endpoint_UserID. This is a little bit confused.
I need to know which user create/update my documents, so I want add username to document.If I add only UserID , I may have a problem with channels (user sees only the documents that he created).


#4

What platforms are you using for Couchbase Lite? If you must know the username of the current user, have you considered implementing the implicit flow instead ?
This forum post may also be relevant to you - CBL database name
Also, if you can elaborate a bit more on what you want to accomplish, we could see if we can do it with just the user Id


#5

I create app in ionic cordova and using REST API for Couchbase Lite. I using also implicit flow.

            "oidc": { "default_provider": "keycloak",
            "providers": {
                "keycloak": {
                    "issuer":"https://localhost:2524/auth/realms/master",
                    "client_id":"client_id",
                    "signing_method": "implicit",
                    "register": true
                }
            }
        }

UserID in keycloak and couchbase user name are different.
keycloak: user1
couchbase: localhost%3A2524%2auth%2realms%2master_user1

I want to accomplish simple thing: user can create document like this:

{
“user_name”: "user1"
“otherImportantInfo” :“other important info”
}

And user has own channel:

“sync”:
function sync(doc, oldDoc) {
requireUser(doc.user_name);
channel(doc._id);
access(doc.user_name, doc._id);
}

The difference in UserId causes problems. If I use keycloak userId in doc, the requireUser is not recognized. If I want to use couchbase user name, I don’t know how to get it.