"Allow the use of multiple user back-ends" ставим галку.
"Add identity provider".
General. "Attribute to map the UID to" = username
"Optional display name of the identity provider..." = "SAML Keycloak"
Service Provider Data. Нажимаю "Show Service Provider settings…".
В поле "X.509 Certificate of Service provider" копирую содержимое файла (сертификат) nextcloud-tst2.example.org.cert .
В поле "Private Key of service provider" копирую содержимое файла (закрытый ключ) nextcloud-tst2.example.org.key .
Identity Provider Data. "Identifier of IdP entity" = https://keycloak-tst.example.org/auth/admin/demo-1
"URL Target of the IdP where the SP will send the Authentication Request Message" = https://keycloak-tst.example.org/auth/admin/demo-1/protocol/saml .
Нажимаю "Show optional Identity Provider settings…". "URL Location of the IdP where the SP will send the SLO Request" = https://keycloak-tst.example.org/auth/admin/demo-1/protocol/saml .
В поле "Public x.509 certificate of the IdP" вставляю содержимое файла keycloak-tst_demo-1_rsa.cert . В моем файле не оказалось строк "-----BEGIN CERTIFICATE-----" и "-----END CERTIFICATE-----". Добавил.
"Attribute mapping" не трогаю, у меня пусто.
Нажимаю "Show security settings…". Выставляю галки в полях:
"Indicates whether the <samlp:authnrequest> messages sent by this SP will be signed. [Metadata of the SP will offer this info]".
"Indicates whether the <samlp:logoutrequest> messages sent by this SP will be signed."
"Indicates whether the <samlp:logoutresponse> messages sent by this SP will be signed."
"Indicates a requirement for the <samlp:response>, <samlp:logoutrequest> and <samlp:logoutresponse> elements received by this SP to be signed."
"Indicates a requirement for the <saml:assertion> elements received by this SP to be signed. [Metadata of the SP will offer this info] ".
Далее, нажимаю "Download metadata XML" и сохраняю в файл nextcloud-tst.example.org_metadata.xml .
Создаю нового клиента (Create) > Select file > выбираю файл nextcloud-tst.example.org_metadata.xml > Save. При этом в списке клиентов (Clients) появляется запись "https://nextcloud-tst.example.org/apps/user_saml/saml/metadata"
Далее, в настройках клиента (https://nextcloud-tst.example.org/apps/user_saml/saml/metadata) выбираю Mappers и создаю Mapper (Create).
Name = username
Mapper Type = User Property
Property = username
Friendly Name = username
SAML Attribute Name = username
SAML Attribute NameFormat = Basic
В конце нажимаю Save.
Далее настраиваю Client Scopes. Realm demo-1 > Client Scopes > role_list (saml) > Закладка Mappers >role list > "Single Role Attribute" = ON > Save. Если этого не сделать, в nextcloud появится ошибка: "Found an Attribute element with duplicated Name".
По шагам. Проверка.
Захожу на сайт на сайт https://nextcloud-tst.example.org/. Выбираю "SAML Keycloak".
На странице keycloak захожу (логинюсь) под user1 и вижу файлы и папки nextcloud.
Замечания. Прочее.
Если имя (логин) "внешнего" (keycloak) пользователя совпадает с именем внутреннего пользователя (например, админа), то "внешний" пользователь получит доступ к файлам внутреннего.