Iām setting up Couchbase Lite on android with Sync Gateway 2.1 and Couchbase Server 6.0.
I've implemented authentication with Google Sign-in by using the OpenID Connect Implicit flow and I'm able to get the session cookie for authentication.
Now I need authorization to use the "requireUser()" function in the SGW config file's javascript, but I can't get SGW to create the User for me.
From what I read in the docs, setting "register":true
in the config file should make SGW automatically create the user when it doesn't exist, but I keep getting an Unauthorized
response when sending a request to /_session
with as body { "name": "new_user_name" }
.
What am I missing to be able to create the user with SGW automatically? I have setup Implicit Flow auth to avoid having to manage my own web app for authorization, so I would like to avoid having to use the Admin rest API for user creation.
Here's my SGW config file:
{
"log": ["*"],
"adminInterface": ":4985",
"databases": {
"lucidity": {
"server": "http://xxx.xxx.xxx.xxx:8091",
"bucket": "bucketname",
"username": "syncgateway",
"password": "***********",
"num_index_replicas": 0,
"enable_shared_bucket_access": true,
"import_docs": "continuous",
"oidc": {
"providers": {
"GoogleAuthFlow": {
"issuer":"https://accounts.google.com",
"client_id":"xxxxxxxxxxxxx.apps.googleusercontent.com ",
"validation_key":" xxxxxxxxxxxx",
"callback_url": "http://xxx.xxx.xxx.xxx:4984/bucketname/_oidc_callback",
"register":true
}
}
},
"users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } },
"sync": `function (doc, oldDoc) {
}`
}
}
EDIT: Here's the log for my request:
POST http://xx.xx.xx.xx:4984/bucketname/_session
Content-Type: application/json
Content-Length: 2
Authorization: [MY_ID_TOKEN_HERE]
Body: { }
And the response is
{
"authentication_handlers" : [ "default", "cookie" ],
"ok" : true,
"userCtx" : {
"channels" : {
"!" : 1,
"*" : 1
},
"name" : null
}
}
with the following Set-Cookie header:
Set-Cookie: SyncGatewaySession=xxxx; Path=/bucketname; Expires=Fri, 18 Jan 2019 08:50:36 GMT