I am trying to setup Keycloak as a IdP (Identity Provider) and Nextcloud as a service. I want to setup Keycloak as to present a SSO (single-sign-on) page.
I am running a Linux-Server with a Intel compatible CPU. What is the correct configuration?
- Keycloak will be running as https://kc.domain.com
- Nextcloud will be running as https://nc.domain.com
Prerequisite
To use this answer you will need to replace
domain.com
with a actual domain you own. Also replaceemail@domain.com
with your working e-mail address.It is assumed you have docker and docker-compose installed and running.
Setup your services with Docker
In addition to keycloak and nextcloud I use:
I'm setting up all the needed service with docker and docker-compose. This is how the
docker-compose.yml
looks like this:I put my docker-files in a folder
docker
and within this folder a project-specific folder. Herekeycloak
. Create them with:Create the
docker-compose.yml
-File with your preferred editor in this folder. Start the services with:Wait a moment to let the services download and start. Check if everything is running with:
If a service isn't running. Issue a second
docker-compose up -d
and check again.Configure Keycloak, add a new Realm
Open a browser and go to https://kc.domain.com . Click on Administration Console. As specified in your
docker-compose.yml
, Username and Password isadmin
.On the top-left of the page you need to create a new Realm. Click
Add
. Enter my-realm as name. ClickSave
.Click on the
Keys
-tab. Look at theRSA
-entry. We will need to copy the Certificate of that line. Click onCertificate
and copy-paste the content to a text editor for later use.Prepare a Private Key and Certificate for Nextcloud
Open a terminal and issue:
This creates two files:
private.key
andpublic.cert
which we will need later for the nextcloud service.Configure Nextcloud
Open a browser and go to https://nc.domain.com . As specified in your
docker-compose.yml
, Username and Password isadmin
.You need to activate the
SSO & Saml Authenticate
which is disabled by default.Important From here on don't close your current browser window until the setup is tested and running. If you close the browser before everything works you probably not be able to change your settings in nextcloud anymore. In such a case you will need to stop the nextcloud- and nextcloud-db-container, delete their respective folders, recreate them and start all over again.
Click on top-right gear-symbol and the then on the
+ Apps
-sign. On the left now see a Menu-bar with the entrySecurity
. Click it. You now see all security realted apps. Click on theActivate
button below theSSO & SAML authentication
App.Click on top-right gear-symbol again and click on
Admin
. Click onSSO & SAML authentication
.Use the following values:
public.cert
into the 'X.509 Certificate'-fieldprivate.key
into the 'Private key of Service Provider'-field.Keys
-tab ofmy-realm
. You will need to add '-----BEGIN CERTIFICATE-----' in front of the key and '-----END CERTIFICATE-----' to the end of it.Download metadata XML
and save the file for the next step.Metadata valid
beside theDownload metadata XML
-ButtonDownload metadata XML
-Button. This generate and send a XML file. Save it.Configure Keycloak, Client
Access the Administror Console again. Click on
Clients
and on the top-right click on theCreate
-Button.Next to Import, Click the
Select File
-Button. Select the XML-File you've create on the last step in Nextcloud.Change:
and click
Save
.You are presented with a new screen. Change the following fields:
Save
On the Tab
Matters
:Delete
-Button on the preassignedrole list
Create
Save
Create
Save
Create
Save
Configure Keycloak, Add user
Users
Add users
Save
Credentials
:Reset Password
Change Password
Test run
Open a new browser window in incognito/private mode. Eg. for google-chrome press
Ctrl-Shift-N
, in Firefox pressCtrl-Shift-P
. Keep the other browser window with the nextcloud setup page open. Else you might lock yourself out.Access https://nc.domain.com with the incognito/private browser window. You are presented with the keycloak username/password page. Enter
user
as name and password. You should be greeted to with the nextcloud welcome screen.Acknowledgement
Here is a slightly updated version for nextcloud 15/16:
Open a browser and go to https://kc.domain.com . Click on Administration Console. As specified in your docker-compose.yml, Username and Password is admin.
On the top-left of the page you need to create a new Realm. Click Add. Enter my-realm as name. Click Save.
Click on the Keys-tab. Look at the RSA-entry. We will need to copy the Certificate of that line. Click on Certificate and copy-paste the content to a text editor for later use. Prepare a Private Key and Certificate for Nextcloud
Open a terminal and issue:
openssl req -nodes -new -x509 -keyout private.key -out public.cert
This creates two files: private.key and public.cert which we will need later for the nextcloud service. Configure Nextcloud
Open a browser and go to https://nc.domain.com . As specified in your docker-compose.yml, Username and Password is admin.
You need to activate the SSO & Saml Authenticate which is disabled by default.
Important From here on don't close your current browser window until the setup is tested and running. If you close the browser before everything works you probably not be able to change your settings in nextcloud anymore. In such a case you will need to stop the nextcloud- and nextcloud-db-container, delete their respective folders, recreate them and start all over again.
Click on top-right gear-symbol and the then on the + Apps-sign. On the left now see a Menu-bar with the entry Security. Click it. You now see all security realted apps. Click on the Activate button below the SSO & SAML authentication App.
Click on top-right gear-symbol again and click on Admin. Click on SSO & SAML authentication.
Use the following values:
Configure Keycloak, Client
Access the Administror Console again. Click on Clients and on the top-right click on the Create-Button.
Next to Import, Click the Select File-Button. Select the XML-File you've create on the last step in Nextcloud.
Change:
and click Save.
You are presented with a new screen. Change the following fields:
On the Tab Matters:
Click Create
Click Create
Configure Keycloak, Add user