{"id":10265,"date":"2026-01-28T23:20:18","date_gmt":"2026-01-29T07:20:18","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/syncgateway-openid-auth\/"},"modified":"2026-01-28T23:20:18","modified_gmt":"2026-01-29T07:20:18","slug":"syncgateway-openid-auth","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/","title":{"rendered":"OpenID Connect Authentication for Sync Gateway with Keycloak"},"content":{"rendered":"\n<h3 id=\"h-introduction\" class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sync Gateway supports OpenID Connect. This allows your application to use Couchbase for data synchronization and delegate the authentication to a 3rd party server known as the OpenID Connect Provider (OP), <a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/authentication.html#openid-connect\">See Here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The goal of this tutorial is to set up and configure the different components participating in this authentication process:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. a client : a Java App using, among other libraries, the Mobile CB-Lite Java SDK 2.7.0,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. an OIDC Service Provider (OP) : Keycloak,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. an OIDC Service Consumer (OC) : Sync Gateway, receiving users credentials from OP and in charge for the authorization part,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Couchbase Server storing data and the users profiles (<code>__sync:user:KEYCLOAKID_<\/code> records) .<\/p>\n\n\n\n<h3 id=\"h-role-of-the-openid-connect-service-provider\" class=\"wp-block-heading\">Role of the OpenID Connect Service Provider<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Keycloak (<a href=\"https:\/\/www.keycloak.org\/\">see<\/a>) has been chosen as the OP for this tutorial as it is well-known open-source, free and Red hat supported component. It is an open source identity and access management solution that can obviously do more than offering an OIDC Service Provider : it can also perform Identify federation, SSO, support other protocols like SAML,&#8230;\nFor more information, <a href=\"https:\/\/www.keycloak.org\/docs\/latest\/getting_started\/index.html\">see<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the context of this tutorial, two Keycloak (KC) features will be used:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. KC OpenID Connect Service Provider<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. KC Identity Service Provider (using built-in KC users database)<\/p>\n\n\n\n<h3 id=\"h-role-of-the-client\" class=\"wp-block-heading\">Role of the client<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The source code of this tutorial is mainly adapted from the Java CB-Lite &#8220;Get Started App&#8217; project (<a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/2.7\/java-platform.html#building-a-getting-started-app\">see<\/a>). It will perform the retrieval of the ID token and create a user session on the Sync Gateway using the POST \/{db}\/_session endpoint on the Public REST API with the ID token.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This <strong>GettingStartedWithOpenIDConnect<\/strong> app demonstrates how to :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Set up an OIDC authentication workflow with Keycloak using the Implicit Flow method<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. Use basic functionality of Couchbase Lite Java (replication and use of different channels).<\/p>\n\n\n\n<h3 id=\"h-role-of-the-sync-gateway\" class=\"wp-block-heading\">Role of the Sync Gateway<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With the implicit workflow method, the Sync Gateway will <em>only<\/em> validate the token, based on the provider definition (<a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/config-properties.html#databases-foo_db-oidc-providers-foo_provider\">see attributes defined in<\/a>)<\/p>\n\n\n\n<h3 id=\"h-role-of-couchbase-server\" class=\"wp-block-heading\">Role of Couchbase Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As we are using the Sync Gateway, the Couchbase Server cluster will store :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Some business data (as usual),\n<strong>2<\/strong>. Also some <strong><em>user<\/em><\/strong> documents generated by the Sync Gateway<\/p>\n\n\n\n<h3 id=\"h-physical-architecture\" class=\"wp-block-heading\">Physical architecture<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Keycloak, Sync Gateway and Couchbase Server components will be deployed as Docker containers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At the opposite, the App client will be compiled and run locally on your machine: it will always you to run it with different options and, as a developer, to be open in Eclipse if you wish to.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/physical_architecture.png\" alt=\"Architecture\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker containers will be named <code>cb-server<\/code>, <code>sync-gateway<\/code> and <code>keycloak<\/code> : they will share a common bridge network named &#8220;workshop2&#8221;. As a consequence, they can reach each other based on their name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From the host (local machine) point-of-view, ports to those applications will be exposed and forwarded (using those same ports) to the host machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nevertheless those names are unknown from that host machine and should therefore be added inside the <code>\/etc\/hosts<\/code> file of your local machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Declare those entries in your <code>\/etc\/hosts<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>vi \/etc\/hosts\n\n# edit \/etc\/hosts by mapping those names to localhost\n127.0.0.1 localhost _machineName_ cb-server sync-gateway keycloak\n#  note : &quot;_machineName_&quot; is your specific machine name (do not change it)\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-deployment\" class=\"wp-block-heading\">Deployment<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Three docker containers wil be deployed :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. one one-node Couchbase Server 6.5 instance named <code>cb-server<\/code>\n<strong>2<\/strong>. one Sync Gateway 2.7.2 instance named <code>sync-gateway<\/code>\n<strong>3<\/strong>. one Keycloak instance named keycloak`<\/p>\n\n\n\n<h4 id=\"h-pre-requisites\" class=\"wp-block-heading\">Pre requisites<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. All the resources files and Java App source code are available inside the <code>OpenID_connect_tutorial<\/code> repository. Open a terminal (TERM1), select a folder to host the git repository and clone the repository:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git clone https:\/\/github.com\/couchbaselabs\/OpenID_connect_tutorial\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The repository structure should look like:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"\/tutorials\/tutorial-syncgateway-openid-auth\/repo_folder_content.png\">width=80%<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. As the tutorial is using Docker containers, Docker version 2.2.0.4 or above is supposed to be installed on your machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. The Java Project (client part) will be running on your local machine and requires maven 3.6.3 or above to be installed (<a href=\"https:\/\/maven.apache.org\/install.html\">see<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Finally, basic operations like cluster\/bucket creation are assumed to be known:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-nodes\/create-cluster.html#provision-a-node-with-the-ui\">Cluster creation<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6<\/strong>. <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-buckets\/create-bucket.html\">Bucket creation<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7<\/strong>. <a href=\"https:\/\/docs.couchbase.com\/server\/current\/tools\/cbimport-json.html\">Import data using the cbimport` command line tool<\/a><\/p>\n\n\n\n<h5 id=\"h-create-a-docker-network\" class=\"wp-block-heading\">Create a docker network<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A bridge network named `workshop2 will be used across all the docker containers.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker network create -d bridge workshop2\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-deploy-keycloak\" class=\"wp-block-heading\">Deploy Keycloak<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">By default KC console log will be appended to inside this dedicated terminal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open a <strong><em>new<\/em><\/strong> Bash terminal (TERM2) and run the following docker command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker run -p &quot;8080:8080&quot; --name keycloak --network workshop2 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=password jboss\/keycloak\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">KC is completely started when the logs end up with:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>11:32:00,618 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 67) WFLYUT0021: Registered web context: &#039;\/auth&#039; for server &#039;default-server&#039;\n11:32:01,056 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010: Deployed &quot;keycloak-server.war&quot; (runtime-name : &quot;keycloak-server.war&quot;)\n11:32:01,273 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server\n11:32:01,286 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http:\/\/127.0.0.1:9990\/management\n11:32:01,287 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http:\/\/127.0.0.1:9990\n11:32:01,288 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 8.0.2 (WildFly Core 10.0.3.Final) started in 65894ms - Started 683 of 988 services (701 services are lazy, passive or on-demand)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Leave this TERM2 terminal open for log inspection.<\/p>\n\n\n\n<h5 id=\"h-deploy-couchbase-server-6-5\" class=\"wp-block-heading\">Deploy Couchbase Server 6.5<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Go back to the <em>first<\/em> Bash terminal (TERM1) and run the following docker command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker run -d --name cb-server --network workshop2 -p 8091-8094:8091-8094 -p 11210:11210 couchbase\/server-sandbox:6.5.0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. Once the container is running, using the Couchbase UI or CLI, create a 1-node cluster with data\/query\/index services enabled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. Then create a Couchbase bucket named <strong>french_cuisine<\/strong> (no replica needed) with 100 Mo Memory Quota.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/create-bucket.png\" alt=\"create bucket\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Next operation is to populate the <code>french_cuisine<\/code> bucket with some data from the <code>dataset.txt<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. Get your <code>containerID<\/code> and copy the <code>dataset.txt<\/code> file in the <code>\/opt\/couchbase\/bin<\/code> folder of the Couchbase Server container.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker ps # retrieve the container ID _yourContainerID_ value associated to Couchbase Server\n\ncd OpenID_connect_tutorial\ndocker cp resources\/dataset.txt _yourContainerID_:\/opt\/couchbase\/bin # replace _yourContainerID_ by the previous value\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> in the sample below, <strong><em>yourContainerID<\/em><\/strong> value is <strong>cbd9e10d3962<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/containerID.png\" alt=\"container id\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the same terminal, open a Bash session for your Couchbase docker instance and import data from <code>resources\/dataset.json<\/code> inside the <code>french_cuisine<\/code> bucket:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker exec -it _yourContainerID_ bash\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the bash terminal of the container, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/opt\/couchbase\/bin\/cbimport json -g product::%id% -c localhost -u Administrator -p password -b french_cuisine --format lines -d file:\/\/\/opt\/couchbase\/bin\/dataset.txt\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After this last operation, the <code>french_cuisine<\/code> bucket is now filled with 7 documents:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/bucket_filled.png\" alt=\"bucket filled\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. Finally create a dedicated Couchbase Server account to access <code>french_cuisine<\/code> bucket from the Sync Gateway:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to <code>Security -&gt; Add User<\/code><\/li>\n\n\n<li>Create a Sync Gateway user (i.e. <code>SG_account<\/code>) and choose a password.<\/li>\n\n\n<li>Set the Roles <code>Administration &amp; Global Roles -&gt; Read-Only Admin<\/code> and <code>french_cuisine -&gt; Application Access<\/code><\/li>\n\n\n<li>Click <code>Addd User<\/code> button<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/SG_account_definition.png\" alt=\"SG account definition\"><\/p>\n\n\n\n<h5 id=\"h-deploy-sync-gateway-2-7-2\" class=\"wp-block-heading\">Deploy Sync Gateway 2.7.2<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> before deploying the Sync Gateway:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Ensure previously defined tasks on Couchbase Server tasks are completed.\n<strong>2<\/strong>. Change directory to the <code>resources<\/code> folder containing the Sync Gateway JSON config file and a basic <code>dataset.txt<\/code> JSON file.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>cd resources\n\ndocker run -p 4984-4985:4984-4985 --network workshop2 --name sync-gateway -d -v pwd\/SG_sync-gateway-config-french-cuisine.json:\/etc\/sync_gateway\/sync_gateway.json couchbase\/sync-gateway:2.7.2-enterprise -adminInterface :4985 \/etc\/sync_gateway\/sync_gateway.json\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. Sync Gateway logs can be directly accessed from the local TERM1 using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>docker logs -f sync-gateway\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">At that point 2 local Bash terminals have been used:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. TERM1 is the terminal with KC running and displaying console logs<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. TERM2 is the terminal used for :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. creating the <code>workshop2<\/code> network,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. running the Couchbase Server container,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. running the Sync Gateway container.<\/p>\n\n\n\n<h4 id=\"h-deploy-the-client-app\" class=\"wp-block-heading\">Deploy the client App<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. In TERM1, go back to the <code>Hello_OpenID_Connect<\/code> folder and compile the executable jar file.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>cd ..\/Hello_OpenID_Connect\n\nmvn package\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note 1:<\/strong> By design, the jar file embeds all the necessary dependencies libraries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. Run the client, the help menu should appear:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>cd targets\n\njava -jar Hello_openID_connect-1.0.0.jar\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/execute_CBLITE_client.png\" alt=\"CBLITE Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note 2:<\/strong> For deploying the current project inside Eclipse, at the <code>Hello_OpenID_Connect<\/code> folder level, run the following command to create the <code>.project<\/code> and `.classpath files to be used by Eclipse:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>mvn eclipse:eclipse\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-configurations-amp-explanations\" class=\"wp-block-heading\">Configurations &amp; explanations<\/h3>\n\n\n\n<h4 id=\"h-keycloak-side\" class=\"wp-block-heading\">Keycloak side<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Once KC is started, open your browser to the <a href=\"http:\/\/keycloak:8080\/auth\/admin\">http:\/\/keycloak:8080\/auth\/admin<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>.  Enter the KC admin credentials: <code>admin<\/code> \/ <code>password<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Those credentials were already defined while running the container ( <code>-e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=password<\/code> environment values)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc.png\" alt=\"KC Admin\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. Realm creation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once logged in, we need to create a <em>Keycloak realm<\/em>: a realm manages a set of users, credentials, roles, and groups. A user belongs to and logs into a realm. Realms are isolated from one another and can only manage and authenticate the users that they control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a dedicated realm, for example <code>couchbase<\/code> and click on the <code>Create<\/code> button:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_realm.png\" alt=\"KC Create Realm\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong> : do not use capital letters inside the <code>realm<\/code> name, nor the <code>'realm'<\/code> term.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The realm is then created:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">![KC Create Realm(.\/kc_create_realm2.png)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Client creation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the realm is built, we then need to create the <code>SyncGatewayFrenchCuisine<\/code> client inside this realm.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the left tab, click on <code>Clients<\/code> and then on the <code>Create<\/code> button:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_client.png\" alt=\"KC Create Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Import the <code>KC_SyncGatewayFrenchCuisine.json<\/code> file (located in the <code>resources<\/code> folder) inside KC using the <code>Select file<\/code> button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The updated client configuration is now:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_client2.png\" alt=\"KC Create Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click <code>Save<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">KC switches to the updated client view. Check the following configuration options are properly set:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_client3.png\" alt=\"KC Create Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_client4.png\" alt=\"KC Create Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_client5.png\" alt=\"KC Create Client\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> all other properties can remain unchanged.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. Users creation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">KC can connect to various sources via User Federation (LDAP and Kerberos) but also offers built-in storage for users and roles  (<a href=\"https:\/\/www.keycloak.org\/docs\/latest\/server_installation\/#_database\">see here<\/a>). In this tutorial, we will be using this KC built-in storage. Please refer to the KC documentation for other User Federation technics (<a href=\"https:\/\/www.keycloak.org\/docs\/6.0\/server_admin\/#_user-storage-federation\">see here<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the left tab, click on <code>Users<\/code> and <code>Add user<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_users.png\" alt=\"KC Create Users\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fill in the form for <code>paul<\/code> user:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_users2.png\" alt=\"KC Create Users\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click the <code>Save<\/code> button.<\/li>\n\n\n<li>Then set the password <code>password<\/code> for <code>paul<\/code> user by:<\/li>\n\n\n<li>clicking on <code>Credentials<\/code>,<\/li>\n\n\n<li>entering paul&#8217;s password twice (i.e. <code>password<\/code>),<\/li>\n\n\n<li>un-checking the <code>Temporary<\/code> checkbox<\/li>\n\n\n<li>finally clicking on <code>Set Password<\/code> and confirm by clicking on <code>Set password<\/code> inside the validation dialog box.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_create_users3.png\" alt=\"KC Create Users\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Repeat these same steps for creating the following users:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wolfgang<\/code><\/li>\n\n\n<li><code>maria<\/code><\/li>\n\n\n<li><code>emmanuel<\/code><\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">At the end, by clicking on <code>View all users<\/code>, the users table should look like this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/kc_users_table.png\" alt=\"KC Users Table\"><\/p>\n\n\n\n<h5 id=\"h-sync-gateway-side\" class=\"wp-block-heading\">Sync Gateway side<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">While deploying the Sync Gateway, a reference to the <code>SG_sync-gateway-config-french-cuisine.json<\/code> JSON configuration file was made. Let see what this document contains:<\/p>\n\n\n\n<pre class=\"wp-block-code language-yml\"><code>{\n  &quot;interface&quot;:&quot;:4984&quot;,\n  &quot;log&quot;: [&quot;*&quot;],\n  &quot;logging&quot;: { &lt;1&gt;\n    &quot;log_file_path&quot;: &quot;\/var\/tmp\/sglogs&quot;,\n    &quot;console&quot;: {\n      &quot;log_level&quot;: &quot;debug&quot;,\n      &quot;log_keys&quot;: [&quot;*&quot;]\n    },\n    &quot;error&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;rotation&quot;: {\n        &quot;max_size&quot;: 20,\n        &quot;max_age&quot;: 180\n      }\n    },\n    &quot;warn&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;rotation&quot;: {\n        &quot;max_size&quot;: 20,\n        &quot;max_age&quot;: 90\n      }\n    },\n    &quot;info&quot;: {\n        &quot;enabled&quot;: true,\n        &quot;rotation&quot;: {\n            &quot;max_size&quot;: 100,\n            &quot;max_age&quot;: 6,\n            &quot;localtime&quot;: false\n        }\n    },\n    &quot;debug&quot;: {\n        &quot;enabled&quot;: false,\n        &quot;rotation&quot;: {\n            &quot;max_size&quot;: 100,\n            &quot;max_age&quot;: 2,\n            &quot;localtime&quot;: false\n        }\n    }\n  },\n  &quot;databases&quot;: {\n    &quot;french_cuisine&quot;: { &lt;2&gt;\n      &quot;bucket_op_timeout_ms&quot;: 5000,\n      &quot;server&quot;: &quot;http:\/\/cb-server:8091&quot;, &lt;3&gt;\n      &quot;bucket&quot;: &quot;french_cuisine&quot;,\n      &quot;username&quot;: &quot;SG_Account&quot;, &lt;4&gt;\n      &quot;password&quot;: &quot;password&quot;, &lt;5&gt;\n      &quot;enable_shared_bucket_access&quot;: true,\n      &quot;import_docs&quot;: true,\n      &quot;num_index_replicas&quot;: 0,\n      &quot;roles&quot;: { &lt;6&gt;\n        &quot;Bretagne_region_role&quot;: {\n          &quot;admin_channels&quot;: [ &quot;Bretagne_region&quot; ]\n        },\n        &quot;Alsace_region_role&quot;: {\n          &quot;admin_channels&quot;: [ &quot;Alsace_region&quot; ]\n        },\n        &quot;PACA_region_role&quot;: {\n          &quot;admin_channels&quot;: [ &quot;PACA_region&quot; ]\n        },\n        &quot;France_role&quot;: {\n          &quot;admin_channels&quot;: [ &quot;Bretagne_region&quot;, &quot;Alsace_region&quot;, &quot;PACA_region&quot; ]\n        }\n      },\n      &quot;users&quot;:{ &lt;7&gt;\n          &quot;admin&quot;: {&quot;password&quot;: &quot;password&quot;, &quot;admin_channels&quot;: [&quot;*&quot;]}\n      },\n      &quot;allow_conflicts&quot;: true,\n      &quot;revs_limit&quot;: 20,\n      &quot;oidc&quot;: { &lt;8&gt;\n        &quot;providers&quot;: {\n          &quot;keycloakimplicit&quot;: { &lt;9&gt;\n            &quot;issuer&quot;:&quot;http:\/\/keycloak:8080\/auth\/realms\/couchbase&quot;, &lt;10&gt;\n            &quot;client_id&quot;:&quot;SyncGatewayFrenchCuisine&quot;, &lt;11&gt;\n            &quot;register&quot;: true &lt;12&gt;\n          }\n        }\n      },\n      &quot;sync&quot;: `function (doc, oldDoc) { &lt;13&gt;\n        console.log(&quot;ENTERING sync function...&quot;);\n\n        if (doc.channels) {\n          console.log(&quot;doc.channels = &quot; + doc.channels);\n          channel(doc.channels);\n       }\n\n       console.log(&quot;QUITING sync function.&quot;);\n      }`\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Some logging configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. The database named <code>french_cuisine<\/code> (could be different from the bucket name).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. The Couchbase Server node<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. The Sync Gateway account previously created to access <code>french_cuisine<\/code> bucket from the Sync Gateway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. The Sync Gateway password previously created to access <code>french_cuisine<\/code> bucket from the Sync Gateway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6<\/strong>. The roles definition: one channel per region is created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7<\/strong>. The users definition: by default, the <code>admin<\/code> user is created here, accessing all channels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8<\/strong>. The OpenID Connect configuration section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>9<\/strong>. A <code>keycloakimplicit<\/code> provider is defined  (this dummy variable could be replaced by anything else)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>10<\/strong>. The OpenID Connect Service Provider issuer (Keycloak URL endpoint, see previous section).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>11<\/strong>. The <code>client_id<\/code> is defined at OP level (see previous section)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>12<\/strong>. Allow any successful logged-in user in KC to automatically create the equivalent user inside Sync Gateway. Note: define users inside the Sync Gateway does not automatically grant access to any channel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>13<\/strong>. The sync function (<a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/config-properties.html#databases-foo_db-sync\">see here<\/a>) is filtering on <code>doc.channels<\/code> property. Only those documents are <strong><em>channeled<\/em><\/strong> (<a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/sync-gateway-channels.html#add-to-channel\">see here<\/a>) to the corresponding channels.<\/p>\n\n\n\n<h5 id=\"h-java-app-code-side\" class=\"wp-block-heading\">Java App code side<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">With the OIDC implicit method, the client-side is in charge of getting the token from the OP and give it to the Sync Gateway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The authorization workflow can be represented as follows:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/clientauth.png\" alt=\"clientauth\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/authentication.html#openid-connect\">See Here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A) Global Overview<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the method calls to leverage an OpenID Connect authentication for the Sync Gateway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>main<\/code> method inside the <code>GettingStartedWithOpenIDConnect<\/code> class:<\/p>\n\n\n\n<pre class=\"wp-block-code language-java\"><code>. . .\n\n\/\/ =======================================\n\/\/ Add OpenID Connect authentication here.\n\/\/ =======================================\n\n\/\/ get the id_token from user credentials\nString tokenID = OpenIDConnectHelper.getTokenID(user, password); &lt;1&gt;\n\/\/ create session storing the id_token (at SG level)\n\/\/ and save the sessionID inside a cookie\nCookie cookie = OpenIDConnectHelper.createSessionCookie(tokenID); &lt;2&gt;\n\nreplConfig.setAuthenticator(new SessionAuthenticator(cookie.getValue(), StringConstants.SG_COOKIE_NAME)); &lt;3&gt;\n\n. . .\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. The client obtains a signed Open ID token directly from an OpenID Connect provider.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. The client pushes the Open ID token to the Sync Gateway to have it store in session. In response, a cookie containing the sessionID is returned by the Sync Gateway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. Subsequent calls will be authorized based on this sessionID.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s explain the role of these 2 static methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note: The OIDC Authentication with Implicit Flow logic is coded in the <code>OpenIDConnectHelper.java<\/code> file.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Hereafter are some extracted methods from this file.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">B) Get the Open ID token<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Static method <code>String getTokenID(String dbUser, String dbPass)<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-java\"><code>\/**\n  * Compute tokenID from DBUSER \/ DBPASS\n  * \n  * @param dbUser\n  * @param dbPass\n  * @return\n  *\/\npublic static String getTokenID(String dbUser, String dbPass) {\n\n  HttpResponse&lt;String&gt; response1 = Unirest.get(KC_OIDC_AUTH_URL).header(&quot;accept&quot;, &quot;application\/json&quot;) &lt;1&gt;\n      .queryString(&quot;response_type&quot;, &quot;id_token&quot;).queryString(&quot;client_id&quot;, &quot;SyncGatewayFrenchCuisine&quot;)\n      .queryString(&quot;scope&quot;, &quot;openid,id_token&quot;).queryString(&quot;redirect_uri&quot;, SG_DB_URL)\n      .queryString(&quot;nonce&quot;, StringConstants.NONCE).queryString(&quot;state&quot;, StringConstants.STATE).asString();\n\n  \/\/ retrieve the POST method inside the returned fiorm\n  URL postURL = extractPostURL(response1.getBody());\n\n  String basePostURL = postURL.toString().split(&quot;\\?&quot;)[0];\n  System.out.println(&quot;basePostURL = &quot; + basePostURL);\n\n  \/\/ Parse the queryString into Name-Value map\n  Map&lt;String, Object&gt; mapQueryString = null;\n  try {\n    mapQueryString = splitQuery(postURL);\n  } catch (UnsupportedEncodingException e) {\n    System.err.println(e);\n    ;\n  }\n\n  \/\/ Run the Authentication POST request with the given username\/password to\n  \/\/ obtain the id_token.\n  HttpResponse&lt;String&gt; response2 = Unirest.post(basePostURL).header(&quot;accept&quot;, &quot;application\/json&quot;) &lt;2&gt;\n      .queryString(mapQueryString).field(&quot;username&quot;, dbUser).field(&quot;password&quot;, dbPass).asString();\n\n  \/\/ get the id_token\n  List&lt;String&gt; locationHeaderList = response2.getHeaders().get(StringConstants.LOCATION_HEADER_NAME);\n  if (locationHeaderList == null) {\n    throw new IllegalArgumentException(&quot;locationHeaderList is null&quot;);\n  }\n\n  String locationHeader = locationHeaderList.get(0);\n\n  if (locationHeader == null) {\n    throw new IllegalArgumentException(&quot;locationHeader is null&quot;);\n  }\n\n  URL urlWithToken = null;\n  try {\n    urlWithToken = new URL(locationHeader);\n  } catch (MalformedURLException e) {\n    System.err.println(e);\n  }\n\n  Map&lt;String, Object&gt; refParams = splitRef(urlWithToken);\n\n  String idTokenValue = (String) refParams.get(&quot;id_token&quot;);\n  if (idTokenValue == null) {\n    throw new IllegalArgumentException(&quot;id_token is missing&quot;);\n  }\n\n  return idTokenValue;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The client code sends:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. a <strong>first GET request<\/strong> to Keycloak endpoint <code>KC_OIDC_AUTH_URL = http:\/\/keycloak:8080\/auth\/realms\/couchbase\/protocol\/openid-connect\/auth\/<\/code> adding <code>client_id = SyncGatewayFrenchCuisine<\/code> and <code>response_type = id_token<\/code> as query string parameters. The KC response is a login form.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. a <strong>second POST request<\/strong> to KC (extracting the URL from the `action form) with the user credentials and, if successful, KC returns an Open ID token back to the application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By design, this code <strong><em>silently<\/em><\/strong> gets the Open ID token from KC in 2 steps.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>the code extracts the POST URL from the HTML response (from the first request)<\/li>\n\n\n<li>then it does a POST on this second URL (<code>http:\/\/keycloak:8080\/auth\/realms\/couchbase\/login-actions\/authenticate?session_code=..<\/code>) in order to obtain the Open ID token inside the <code>id_token<\/code> response header.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> as oppose to this <em>silent<\/em> option, another option <em>could<\/em> have been to run the <strong>first request<\/strong> in a web-browser to expose the KC UI login screen directly to the end-user and then let the user enters his login\/password and submits the form and perform the <strong>second request<\/strong>: the Open ID token would be contained in the <code>id_token<\/code> response header as well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C) Create a session ID from the Open ID token<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Static method <code>Cookie createSessionCookie(String idTokenValue)<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-java\"><code>\npublic static Cookie createSessionCookie(String idTokenValue) {\n\n  HttpResponse&lt;String&gt; response3 = Unirest.post(&quot;http:\/\/sync-gateway:4984\/french_cuisine\/_session&quot;) &lt;1&gt;\n      .header(&quot;Authorization&quot;, &quot;Bearer &quot; + idTokenValue).asString();\n\n  System.out.println(&quot; &gt;&gt;&gt;&gt; &quot; + response3.getBody());\n\n  Iterator&lt;Cookie&gt; it = response3.getCookies().iterator(); \n  Cookie resCookie = null;\n\n  while (it.hasNext()) {\n    Cookie cookie = it.next();\n    if (StringConstants.SG_COOKIE_NAME.equals(cookie.getName())) {\n      resCookie = cookie; &lt;2&gt;\n      break;\n    }\n  }\n\n  return resCookie;\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The ID token is used to create a Sync Gateway session by sending a POST <code>\/{db}\/_session<\/code> request by including the Open ID token as an <code>Authorization: Bearer &lt;id_token&gt;<\/code> inside the request header.<\/li>\n\n\n<li>Sync Gateway returns a cookie session in the response header (to be used after inside the <code>SessionAuthenticator<\/code> on the replicator object).<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-tests\" class=\"wp-block-heading\">Tests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The tests are mainly focusing on:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>establishing a connection to the Keycloak OP<\/li>\n\n\n<li>give the right access (the right channel) to each  user<\/li>\n\n\n<li>how to use channels to filter results based on different channel roles.<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-test-1-basic-test-for-a-1user-synchronization\" class=\"wp-block-heading\">Test 1 : basic test for a 1-user synchronization<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. Note that, inside the code both the <code>SYNC_GATEWAY_URL<\/code> and Keycloak authentication URL (<code>KC_OIDC_AUTH_URL<\/code>) are <strong>hard-coded<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>SYNC_GATEWAY_URL<\/code> :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>http version : <code>http:\/\/sync-gateway:4984\/french_cuisine\/<\/code><\/li>\n\n\n<li>websocket version : <code>ws:\/\/sync-gateway:4984\/french_cuisine<\/code><\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><code>KC_OIDC_AUTH_URL<\/code> : <code>http:\/\/keycloak:8080\/auth\/realms\/couchbase\/protocol\/openid-connect\/auth\/<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. Run the java client App :<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb java -jar Hello_openID_connect-1.0.0.jar -u paul -p password\nDB_PATH = \/Users\/fabriceleray\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target\/resources\nW\/CouchbaseLite\/DATABASE:Database.log.getFile().getConfig() is now null: logging is disabled.  Log files required for product support are not being generated.\n== Executing Query 1\nQuery returned 0 rows of type product\nbasePostURL = http:\/\/keycloak:8080\/auth\/realms\/couchbase\/login-actions\/authenticate\navr. 13, 2020 4:30:29 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies\nAVERTISSEMENT: Invalid cookie header: &quot;Set-Cookie: SyncGatewaySession=b098ac3426f20bfb3e5fe6eb65fa80174e7eeb43; Path=\/french_cuisine; Expires=Tue, 14 Apr 2020 14:30:29 GMT&quot;. Invalid &#039;expires&#039; attribute: Tue, 14 Apr 2020 14:30:29 GMT\n &gt;&gt;&gt;&gt; {&quot;authentication_handlers&quot;:[&quot;default&quot;,&quot;cookie&quot;],&quot;ok&quot;:true,&quot;userCtx&quot;:{&quot;channels&quot;:{&quot;!&quot;:1},&quot;name&quot;:&quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_05b2ad6c-598d-44a5-9eca-4b8b671cd84c&quot;}}\nW\/CouchbaseLite\/REPLICATOR:Replicator{@17c386de,&lt;*&gt;,Database{@4534b60d, name=&#039;french_cuisine&#039;},URLEndpoint{url=ws:\/\/sync-gateway:4984\/french_cuisine}]: received unrecognized activity level:\n== Executing Query 3\nTotal rows returned by query = 0\n== Executing Query 3\nTotal rows returned by query = 0\n^C%\n\n~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. <strong>Note<\/strong> that:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The replication process has run successfully : a <code>\/resources\/<\/code> folder containing <code>french_cuisine.cblite2<\/code> file have been created:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb ll resources\ntotal 0\ndrwxr-xr-x  2 fabriceleray  staff    64B 13 avr 16:31 CouchbaseLiteTemp\ndrwx------  6 fabriceleray  staff   192B 13 avr 16:31 french_cuisine.cblite2\n\n~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">no data has been replicated to the local database (<code>Total rows returned by query = 0<\/code>). <strong>Why that?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is because, despite the <code>authentication<\/code> process was successful, the <code>authorization<\/code> process is still handled by the Sync Gateway. At that point, <code>paul<\/code> user is <em>not<\/em> linked to any channels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To check this thing, open Couchbase Server <code>Documents<\/code> tab and search for <code>_sync:user:keycloak_PAUL_ID_<\/code>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/paul_sync_document.png\" alt=\"Sync Document\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>keycloak userID<\/code> linked to <code>paul<\/code> user has to be given access to the channels he should belong to, that is to say : paul should be granted access to channel role <code>Bretagne_region_role<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To perform such operation, we need to change paul&#8217;s channel access role (<a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/users-and-roles.html\">see here<\/a> and <a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/admin-rest-api.html#\/user\/put__db___user__name_\">here<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following curl command (adapting the <code>keycloak userID<\/code> value to yours) to change paul&#8217;s role channel settings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>curl -X PUT &quot;http:\/\/localhost:4985\/french_cuisine\/_user\/keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_05b2ad6c-598d-44a5-9eca-4b8b671cd84c&quot; -H &quot;accept: application\/json&quot; -H &quot;Content-Type: application\/json&quot; -d &quot;{ &quot;name&quot;: &quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_05b2ad6c-598d-44a5-9eca-4b8b671cd84c&quot;, &quot;password&quot;: &quot;password&quot;, &quot;admin_roles&quot;: [ &quot;Bretagne_region_role&quot; ], &quot;email&quot;: &quot;paul@paul.com&quot;, &quot;disabled&quot;: false}&quot;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Refresh your Couchbase Sever Document page in your browser and check again <code>_sync:user:keycloak_PAUL_ID_<\/code>. Paul&#8217;s channel roles have changed:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/paul_sync_document2.png\" alt=\"Sync Document\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: of course, it is also possible to directly create users with associated <code>admin_roles<\/code> <em>before<\/em> user first log in attempt using POST REST calls (<a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/2.7\/admin-rest-api.html#\/user\/post__db___user_\">see here<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Re-run the java client App:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb rm -f resources # to be sure to restart from a fresh local database\n~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb java -jar Hello_openID_connect-1.0.0.jar -u paul -p password\nDB_PATH = \/Users\/fabriceleray\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target\/resources\nW\/CouchbaseLite\/DATABASE:Database.log.getFile().getConfig() is now null: logging is disabled.  Log files required for product support are not being generated.\n== Executing Query 1\nQuery returned 0 rows of type product\nbasePostURL = http:\/\/keycloak:8080\/auth\/realms\/couchbase\/login-actions\/authenticate\navr. 13, 2020 5:06:57 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies\nAVERTISSEMENT: Invalid cookie header: &quot;Set-Cookie: SyncGatewaySession=018241ac94b0c92b70fb1e31ce9538e21581a034; Path=\/french_cuisine; Expires=Tue, 14 Apr 2020 15:06:57 GMT&quot;. Invalid &#039;expires&#039; attribute: Tue, 14 Apr 2020 15:06:57 GMT\n &gt;&gt;&gt;&gt; {&quot;authentication_handlers&quot;:[&quot;default&quot;,&quot;cookie&quot;],&quot;ok&quot;:true,&quot;userCtx&quot;:{&quot;channels&quot;:{&quot;!&quot;:1},&quot;name&quot;:&quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_05b2ad6c-598d-44a5-9eca-4b8b671cd84c&quot;}}\nW\/CouchbaseLite\/REPLICATOR:Replicator{@17c386de,&lt;*&gt;,Database{@4534b60d, name=&#039;french_cuisine&#039;},URLEndpoint{url=ws:\/\/sync-gateway:4984\/french_cuisine}]: received unrecognized activity level:\nDocument product::05_galette has been replicated !!\nDocument product::06_saucisse has been replicated !!\n== Executing Query 3\n1 ... Id: product::05_galette is learning: galette version: 0,00 type is product\n2 ... Id: product::06_saucisse is learning: saucisse version: 0,00 type is product\nTotal rows returned by query = 2\n== Executing Query 3\n1 ... Id: product::05_galette is learning: galette version: 0,00 type is product\n2 ... Id: product::06_saucisse is learning: saucisse version: 0,00 type is product\nTotal rows returned by query = 2\n^C%\n~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now the replication is done for Paul for documents whose channels are belonging to <code>Bretagne_region_role<\/code> role:<\/p>\n\n\n\n<pre class=\"wp-block-code language-yml\"><code> &quot;Bretagne_region_role&quot;: {\n          &quot;admin_channels&quot;: [ &quot;Bretagne_region&quot; ]\n        },\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As documents <code>product::05_galette<\/code> and <code>product::06_saucisse<\/code> are associated to the <code>Bretagne_region<\/code> channel, they are successfully replicated to paul&#8217;s local database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. Stop the process (<code>Ctrl+C<\/code>) and  re-run the executable adding one more document to the local database (adding optional arguments <code>-d 1 -c Bretagne_region<\/code> to the previous command line):<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb java -jar Hello_openID_connect-1.0.0.jar -u paul -p password -d 1 -c Bretagne_region\nOption create-doc is present.  The value is: 1\nOption channel is present.  The value is: Bretagne_region\nDB_PATH = \/Users\/fabriceleray\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target\/resources\nW\/CouchbaseLite\/DATABASE:Database.log.getFile().getConfig() is now null: logging is disabled.  Log files required for product support are not being generated.\nDocument ID is :: produit_from_CBL_f9fb9e1e-7681-4d0f-8a77-dbefc62457bc\nName 22mdufI\nPrice 1.5558478281279886\nChannels Bretagne_region\n== Executing Query 1\nQuery returned 3 rows of type product\nbasePostURL = http:\/\/keycloak:8080\/auth\/realms\/couchbase\/login-actions\/authenticate\navr. 13, 2020 5:28:06 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies\nAVERTISSEMENT: Invalid cookie header: &quot;Set-Cookie: SyncGatewaySession=2779cfba9ecf72755bc290daeceddd27267e18d6; Path=\/french_cuisine; Expires=Tue, 14 Apr 2020 15:28:06 GMT&quot;. Invalid &#039;expires&#039; attribute: Tue, 14 Apr 2020 15:28:06 GMT\n &gt;&gt;&gt;&gt; {&quot;authentication_handlers&quot;:[&quot;default&quot;,&quot;cookie&quot;],&quot;ok&quot;:true,&quot;userCtx&quot;:{&quot;channels&quot;:{&quot;!&quot;:1},&quot;name&quot;:&quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_05b2ad6c-598d-44a5-9eca-4b8b671cd84c&quot;}}\nW\/CouchbaseLite\/REPLICATOR:Replicator{@3bd40a57,&lt;*&gt;,Database{@4534b60d, name=&#039;french_cuisine&#039;},URLEndpoint{url=ws:\/\/sync-gateway:4984\/french_cuisine}]: received unrecognized activity level:\nDocument produit_from_CBL_f9fb9e1e-7681-4d0f-8a77-dbefc62457bc has been replicated !!\n== Executing Query 3\n1 ... Id: product::05_galette is learning: galette version: 0,00 type is product\n2 ... Id: product::06_saucisse is learning: saucisse version: 0,00 type is product\n3 ... Id: produit_from_CBL_f9fb9e1e-7681-4d0f-8a77-dbefc62457bc is learning: 22mdufI version: 1,56 type is product\nTotal rows returned by query = 3\n^C%\n~\/eclipse-workspace\/HelloWorldCBLite2.7\/Hello_OpenID_Connect\/target(master*) \u00bb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6<\/strong>. Check the document <code>produit_from_CBL_f9fb9e1e-7681-4d0f-8a77-dbefc62457bc<\/code> (adapt to your productID) has been replicated to Couchbase Server:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/add_one_more_doc.png\" alt=\"add another document\"><\/p>\n\n\n\n<h5 id=\"h-test-2-advanced-test-with-4-users\" class=\"wp-block-heading\">Test 2 : advanced test with 4 users<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The goal here is to test channel&#8217;s filtering. Each user is linked to 1 channel except for <code>emmanuel<\/code> whose role is <code>France_role<\/code> and is therefore linked to the 3 channels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1<\/strong>. In the <code>target<\/code> folder, create a <code>temp<\/code> directory and 4 subdirectories named <code>paul<\/code>, <code>wolfgang<\/code>, <code>maria<\/code> and <code>emmanuel<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2<\/strong>. Create 4 copies of the target directory inside those folders:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>mkdir -p temp\/paul\nmkdir -p temp\/wolfgang\nmkdir -p temp\/maria\nmkdir -p temp\/emmanuel\n\ncp Hello_openID_connect-1.0.0.jar temp\/paul\ncp Hello_openID_connect-1.0.0.jar temp\/wolfgang\ncp Hello_openID_connect-1.0.0.jar temp\/maria\ncp Hello_openID_connect-1.0.0.jar temp\/emmanuel\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3<\/strong>. Open 4 terminals (TERM1, TERM2, TERM3 and TERM4) and <code>cd<\/code> to the corresponding folders above and run the client App once for each user.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>TERM1:\njava -jar Hello_openID_connect-1.0.0.jar -u paul -p password\n\nTERM2:\njava -jar Hello_openID_connect-1.0.0.jar -u wolfgang -p password\n\nTERM3:\njava -jar Hello_openID_connect-1.0.0.jar -u maria -p password\n\nTERM4:\njava -jar Hello_openID_connect-1.0.0.jar -u emmanuel -p password\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4<\/strong>. Note that:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Couchbase Server, each user has now his <code>__sync:user:KEYCLOAKID_<\/code> document.\nNo document is replicated (except for <code>paul<\/code> because his channel role was defined during <code>Test 1<\/code>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5<\/strong>. Change channels to <code>wolfgang<\/code>, <code>maria<\/code> and <code>emmanuel<\/code>. In any terminal, run the following curl commands:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>curl -X PUT &quot;http:\/\/localhost:4985\/french_cuisine\/_user\/keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_e014924e-4b4b-4b48-b772-c79140e4da31&quot; -H &quot;accept: application\/json&quot; -H &quot;Content-Type: application\/json&quot; -d &quot;{ &quot;name&quot;: &quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_e014924e-4b4b-4b48-b772-c79140e4da31&quot;, &quot;password&quot;: &quot;password&quot;, &quot;admin_roles&quot;: [ &quot;Alsace_region_role&quot; ], &quot;email&quot;: &quot;wolfgang@wolfgang.com&quot;, &quot;disabled&quot;: false}&quot;\n\ncurl -X PUT &quot;http:\/\/localhost:4985\/french_cuisine\/_user\/keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_b5ac69b4-4dc6-46c2-b558-c33b233a1899&quot; -H &quot;accept: application\/json&quot; -H &quot;Content-Type: application\/json&quot; -d &quot;{ &quot;name&quot;: &quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_b5ac69b4-4dc6-46c2-b558-c33b233a1899&quot;, &quot;password&quot;: &quot;password&quot;, &quot;admin_roles&quot;: [ &quot;PACA_region_role&quot; ], &quot;email&quot;: &quot;maria@maria.com&quot;, &quot;disabled&quot;: false}&quot;\n\ncurl -X PUT &quot;http:\/\/localhost:4985\/french_cuisine\/_user\/keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_f7715f9c-fa3b-49c6-b442-00df719a2402&quot; -H &quot;accept: application\/json&quot; -H &quot;Content-Type: application\/json&quot; -d &quot;{ &quot;name&quot;: &quot;keycloak%3A8080%2Fauth%2Frealms%2Fcouchbase_f7715f9c-fa3b-49c6-b442-00df719a2402&quot;, &quot;password&quot;: &quot;password&quot;, &quot;admin_roles&quot;: [ &quot;France_role&quot; ], &quot;email&quot;: &quot;emmanuel@emmanuel.com&quot;, &quot;disabled&quot;: false}&quot;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the channel&#8217;s role are applied to the users:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wolfgang:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/wolfgang.png\" alt=\"Role Wolfgang\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Maria:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/maria.png\" alt=\"Role Maria\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Emmanuel:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/emmanuel.png\" alt=\"Role Emanuel\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6<\/strong>. Now re-run the java client App and observe the differences:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Paul:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/paul_res.png\" alt=\"Observe Paul\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wolfgang:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/wolfgang_res.png\" alt=\"Observe Wolfgang\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Maria:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/maria_res.png\" alt=\"Observe Maria\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Emmanuel:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/emmanuel_res.png\" alt=\"Observe Emanuel\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7<\/strong>. As expected, adding 2 new products for <code>PACA_region<\/code> makes some change in <code>maria<\/code> and <code>emmanuel<\/code> results.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>java -jar Hello_openID_connect-1.0.0.jar -u maria -p password -d 2 -c PACA_region\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8<\/strong>. Check <code>maria<\/code> and <code>emmanuel<\/code> results (results for other users remain unchanged):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Maria:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/maria_res2.png\" alt=\"Check Maria\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Emmanuel:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/emmanuel_res2.png\" alt=\"Check Emanuel\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Sync Gateway supports OpenID Connect. This allows your application to use Couchbase for data synchronization and delegate the authentication to a 3rd party server known as the OpenID Connect Provider (OP), See Here The goal of this tutorial is to set up and configure the different components participating in this authentication process: 1. a client : a Java App using, among other libraries, the Mobile CB-Lite Java SDK 2.7.0, 2. an OIDC Service Provider (OP) : Keycloak, 3. an OIDC Service Consumer (OC) : Sync Gateway, receiving users credentials from OP and in charge for the authorization part, 4. Couchbase Server storing data and the users profiles (__sync:user:KEYCLOAKID_ records) [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[595,582,593,594],"tutorial-tags":[598,600,599],"tutorial-technologies":[585,597],"tutorial-types":[555],"class_list":["post-10265","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-android-java","tutorial-languages-csharp","tutorial-languages-objective-c","tutorial-languages-swift","tutorial-tags-authentication","tutorial-tags-keycloak","tutorial-tags-openid","tutorial-technologies-mobile","tutorial-technologies-sync-gateway","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>OpenID Connect Authentication for Sync Gateway with Keycloak - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenID Connect Authentication for Sync Gateway with Keycloak\" \/>\n<meta property=\"og:description\" content=\"Introduction Sync Gateway supports OpenID Connect. This allows your application to use Couchbase for data synchronization and delegate the authentication to a 3rd party server known as the OpenID Connect Provider (OP), See Here The goal of this tutorial is to set up and configure the different components participating in this authentication process: 1. a client : a Java App using, among other libraries, the Mobile CB-Lite Java SDK 2.7.0, 2. an OIDC Service Provider (OP) : Keycloak, 3. an OIDC Service Consumer (OC) : Sync Gateway, receiving users credentials from OP and in charge for the authorization part, 4. Couchbase Server storing data and the users profiles (__sync:user:KEYCLOAKID_ records) [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"24\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/syncgateway-openid-auth\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/syncgateway-openid-auth\\\/\",\"name\":\"OpenID Connect Authentication for Sync Gateway with Keycloak - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#website\"},\"datePublished\":\"2026-01-29T07:20:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/syncgateway-openid-auth\\\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/syncgateway-openid-auth\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/developers\\\/tutorials\\\/syncgateway-openid-auth\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/ko\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenID Connect Authentication for Sync Gateway with Keycloak\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/ja\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"OpenID Connect Authentication for Sync Gateway with Keycloak - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/","og_locale":"ja_JP","og_type":"article","og_title":"OpenID Connect Authentication for Sync Gateway with Keycloak","og_description":"Introduction Sync Gateway supports OpenID Connect. This allows your application to use Couchbase for data synchronization and delegate the authentication to a 3rd party server known as the OpenID Connect Provider (OP), See Here The goal of this tutorial is to set up and configure the different components participating in this authentication process: 1. a client : a Java App using, among other libraries, the Mobile CB-Lite Java SDK 2.7.0, 2. an OIDC Service Provider (OP) : Keycloak, 3. an OIDC Service Consumer (OC) : Sync Gateway, receiving users credentials from OP and in charge for the authorization part, 4. Couchbase Server storing data and the users profiles (__sync:user:KEYCLOAKID_ records) [&hellip;]","og_url":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"24\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/","url":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/","name":"OpenID Connect Authentication for Sync Gateway with Keycloak - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/ja\/#website"},"datePublished":"2026-01-29T07:20:18+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/ja\/developers\/tutorials\/syncgateway-openid-auth\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/ko\/"},{"@type":"ListItem","position":2,"name":"OpenID Connect Authentication for Sync Gateway with Keycloak"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/ja\/#website","url":"https:\/\/www.couchbase.com\/ja\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/ja\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/ja\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/ja\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/ja\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.couchbase.com\/ja\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/ja\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase\u306f\u30ab\u30ea\u30d5\u30a9\u30eb\u30cb\u30a2\u5dde\u30b5\u30f3\u30ce\u30bc\u306b\u672c\u793e\u3092\u7f6e\u304f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u4f01\u696d\u3067\u3001\u6570\u767e\u306e\u30b0\u30ed\u30fc\u30d0\u30eb\u4f01\u696d\u304c\u4f7f\u7528\u3059\u308bAI\u7528\u306e\u904b\u7528\u30c7\u30fc\u30bf\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials\/10265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorials\/10265\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/media?parent=10265"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-languages?post=10265"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-tags?post=10265"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-technologies?post=10265"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/ja\/wp-json\/wp\/v2\/tutorial-types?post=10265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}