Package: pas.plugins.oidc
pas.plugins.oidcThis is a Plone authentication plugin for OpenID Connect.
OAuth 2.0 should work as well because OpenID Connect is built on top of this protocol.FeaturesPAS plugin, although currently no interfaces are activated.Three browser views for this PAS plugin, which are the main interaction with the outside world.InstallationInstallpas.plugins.oidcby adding it to your buildout:[buildout]

...

eggs =
    pas.plugins.oidcand then runningbin/buildoutWarningPay attention to the customization ofUser info property used as useridfield, with the wrong configuration it’s easy to impersonate another user.Install and configure the pluginGo to the Add-ons control panel and installpas.plugins.oidc.In the ZMI go to the plugin properties athttp://localhost:8080/Plone/acl_users/oidc/manage_propertiesFormConfigure the properties with the data obtained from your provider:OIDC/Oauth2 IssuerClient IDClient secretredirect_uris: this needs to match thepublic URLwhere the user will be redirected after the login flow is completed. It needs to include
the/Plone/acl_users/oidc/callbackpart. When using Volto you need to expose Plone somehow to have the login process finish correctly.Use Zope session data manager: see the section below about the usage of session.Create user / update user properties: when selected the user data in Plone will be updated with the data coming from the OIDC provider.Create authentication __ac ticket: when selected the user will be allowed to act as a logged-in user in Plone.Create authentication auth_token (Volto/REST API) ticket: when selected the user will be allowed to act as a logged-in user in the Volto frontend.Open ID scopes to request to the server: information requested to the OIDC provider. Leave it as it is or modify it according to your provider’s information.Use PKCE: when enabled usesPKCEwhen requesting authentication from the provider.Login and Logout URLsWhen using this plugin withPlone 6 Classic UIthe standard URLs used for login (http://localhost:8080/Plone/login) and logout (http://localhost:8080/Plone/logout)
will not trigger the usage of the plugin.When using this plugin with aVolto frontendthe standard URLs for login (http://localhost:3000/login)
and logout (http://localhost:3000/logout) will not trigger the usage of the plugin.To login into a site using the OIDC provider, you will need to change those login URLs to the following:Login URL: /<Plone Site Id>/acl_users/<oidc pas plugin id>/loginLogout URL: /<Plone Site Id>/acl_users/<oidc pas plugin id>/logoutWhere:Plone Site Id: is the id you gave to the Plone site when you created it. It is usuallyPlonebut may vary. It is the last part of the URL when you browse Plone directly without using any proxy server, ex.http://localhost:8080/Plone+->Plone.oidc pas plugin id: is the id you gave to the OIDC plugin when you created it inside the Plone PAS administration panel. If you just used the default configuration and installed this plugin using Plone’s Add-on Control Panel, this id will beoidc.When using Volto as a frontend, you need to expose those login and logout URLs somehow to make the login and logout process work.Example setup with KeycloakSetup Keycloak as serverPlease refer to theKeycloak documentationfor up to date instructions.
Specifically, here we will use a Docker image, so follow the instructions on how toget started with Keycloak on Docker.
This doesnotgive you a production setup, but it is fine for local development.Note:Keycloak runs on port8080by default. Plone uses the same port. When you are reading this, you probably know how to let Plone use a different port.
So let’s indeed let Keycloak use its preferred port. At the moment of writing, this is how you start a Keycloak container:docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:19.0.3 start-devThe plugin can be used with legacy (deprecated) Keycloakredirect_uriparameter. To use this you need to enable the option
in the plugin configuration. To test that you can run the Keycloak server with the--spi-login-protocol-openid-connect-legacy-logout-redirect-uri=trueoption:docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:19.0.3 start-dev --spi-login-protocol-openid-connect-legacy-logout-redirect-uri=trueNote:when you exit this container, it still exists and you can restart it so you don’t lose your configuration.
Withdocker ps-afigure out the name of the container and then usedocker container start-ai<name>.Follow the Keycloak Docker documentation further:Open theKeycloak Admin Console, make sure you are logged in asadmin.Click the wordmasterin the top-left corner, then clickCreate Realm.Enterplonein theRealm namefield.ClickCreate.Click the wordmasterin the top-left corner, then clickplone.ClickManage->Usersin the left-hand menu.ClickCreate new user.Remember to set a password for this user in theCredentialstab.Open a different browser and check that you can login toKeycloak Account Consolewith this user.In the original browser, follow the steps for securing your first app.
But we will be using different settings for Plone.
And when last I checked, the actual UI differed from the documentation.
So:Open theKeycloak Admin Console, make sure you are logged in asadmin.Click the wordmasterin the top-left corner, then clickplone.ClickManage->Clientsin the left-hand menu.ClickCreate client:Client type:OpenID ConnectClient ID:ploneTurnAlways display in consoletoOn,Useful for testing.ClickNextand clickSave.Now you can fill in theSettings->Access settings. We will assume Plone runs on port8081:Root URL:http://localhost:8081/Plone/Home URL:http://localhost:8081/Plone/Valid redirect URIs:http://localhost:8081/Plone*Tip:Leave the rest at the defaults, unless you know what you are doing.Now you can fill in theSettings->Capability config.TurnClient authenticationtoOn. This defines the type of the OIDC client. When it’s ON, the
OIDC type is set to confidential access type. When it’s OFF, it is set to public access type.ClickSave.Now you can accessCredentials->Client secretand click on the clipboard icon to copy it. This will
be necessary to configure the plugin in Plone.Keycloak is ready done configured!Setup Plone as a clientIn your Zope instance configuration, make sure Plone runs on port 8081.Make surepas.plugins.oidcis installed withpiporBuildout.Start Plone and create a Plone site with id Plone.In the Add-ons control panel, installpas.plugins.oidc.In the ZMI go to the plugin properties athttp://localhost:8081/Plone/acl_users/oidc/manage_propertiesFormSet these properties:OIDC/Oauth2 Issuer:http://localhost:8080/realms/plone/Client ID:ploneWarning:This property must match theClient IDyou have set in Keycloak.Client secret:••••••••••••••••••••••••••••••••Warning:This property must match theClient secretyou have get in Keycloak.Use deprecated redirect_uri for logouturl(/Plone/acl_users/oidc/logout)checked. Use this if you need to run old versions of Keycloak.Open ID scopes to request to the server: this depends on which version of Keycloak you are using, and which scopes are available there.
In recent Keycloak versions, youmustincludeopenidas scope.
Suggestion is to useopenidandprofile.Tip:Leave the rest at the defaults, unless you know what you are doing.ClickSave.Plone is ready done configured!See this screenshot:Warning:Attention, before Keycloak 18, the parameter for logout wasredirect_uriand it has been deprecated since version 18. But the
Keycloak server can run with theredirect_uriif needed, it is possible to use the plugin with the legacyredirect_uriparameter enabled also. The problem is that if the deprecated parameter is enabled in the plugin but not in the server, the plugin
will not work.So, this is the way it works:With legacyredirect_uriparameter enabled in Keycloak, the plugin works in default mode.With legacyredirect_uriparameter enabled in Keycloak, the plugin also works with legacy mode.With legacyredirect_uriparameter disabled in Keycloak (default after version 18), the plugin works in default mode.With legacyredirect_uriparameter disabled in Keycloak (default after version 18), the plugin does NOT work with legacy mode.So, for Keycloak, it does not matter if we use the default or legacy mode if the Keycloak runs in legacy mode.Notes:If legacyredirect_uriparameter is disabled in Keycloak, this is the default since version 18 of Keycloak according
to this comment inStarck Overflow:https://stackoverflow.com/a/72142887.The plugin will work only if theUse deprecated redirect_uri for logouturl(/Plone/acl_users/oidc/logout)option is un-checked at the plugin properties athttp://localhost:8081/Plone/acl_users/oidc/manage_propertiesForm.LoginGo to the other browser, or logout as admin fromKeycloak Admin Console.
Currently, the Plone login form is unchanged.Instead, for testing go to the login page of the plugin:http://localhost:8081/Plone/acl_users/oidc/login,
this will take you to Keycloak to login, and then return. You should now be logged in to Plone, and see thefull nameandemail, if you have set this in Keycloak.LogoutIf the login did work as expected you can try to Plone logout.
Currently, the Plone logout form is unchanged.Instead, for testing go to the logout page of the plugin:http://localhost:8081/Plone/acl_users/oidc/logout,
this will take you to Keycloak to logout, and then return to the post-logout redirect URL.Usage of sessions in the login processThis plugin uses sessions during the login process to identify the user while he goes to the OIDC provider
and comes back from there.The plugin has 2 ways of working with sessions:Use the Zope Session Management: if theUse Zope session data manageroption in the plugin configuration is enabled,
the plugin will use the sessioning configuration configured in Zope. To do so we advise usingProducts.mcdutilsto save the session data in a memcached based storage. Otherwise Zope will try to use ZODB based sessioning
which has shown several problems in the past.Use the cookie-based session management: if theUse Zope session data manageroption in the plugin
configuration is disabled, the plugin will use a Cookie to save that information in the client’s browser.Settings in environment variablesOptionally, instead of editing your OIDC provider settings through the ZMI, you can usecollective.regenvand provide
aYAMLfile with your settings. This is very useful if you have different settings in different environments
and you do not want to edit the settings each time you move the contents.VarnishOptionally, if you are using theVarnish caching serverin front
of Plone, you may see this plugin only partially working. Especially thecame_fromparameter may be ignored.
This is because the buildout standard configuration fromplone.recipe.varnishremoves most cookies to improve anonymous caching.The solution is to make sure the__ac_sessioncookie is added to thecookie-passoption.
Check what the current default is in the buildout recipe, and update it:[varnish-configuration]
recipe = plone.recipe.varnish:configuration
...
cookie-pass = "auth_token|__ac(|_(name|password|persistent|session))=":"\.(js|css|kss)$"ContributeIssue Tracker:https://github.com/collective/pas.plugins.oidc/issuesSource Code:https://github.com/collective/pas.plugins.oidcDocumentation:https://docs.plone.org/foo/barReferencesBlog post:https://www.codesyntax.com/en/blog/log-in-in-plone-using-your-google-workspace-accountLicenseThe project is licensed under the GPLv2.Contributorsmamico,mauro.amico@gmail.comerral, Mikel Larreategialecghica,alec.ghica@eaudeweb.romacagua,leonardocaballero@gmail.comChangelog1.0.0 (2023-11-11)Allow dict instances to hold userinfo
[erral]1.0a6 (2023-07-20)Added Spanish translation
[macagua]Added improvements about i18n support
[macagua]Drop python 2.7 and Plone 4 support
[erral]Add support for the post_logout parameter for logout api.
[ramiroluz]1.0a5 (2023-04-05)Catch exceptions during the OAuth process
[erral]Update the plugin to make challenges.
An anonymous user who visits a page for which you have to be authenticated,
is redirected to the new require_login view on the plugin.
This works the same way as the standard require_login page of Plone.
[maurits]Add a property for the default userinfo instead of using only sub.
[eikichi18]1.0a4 (2023-01-16)Call getProperty only once when getting redirect_uris or scope.
[maurits]use getProperty accessor
[mamico]1.0a3 (2022-10-30)Removed the hardcoded auth cookie name
[alecghica]Fixed Python compatibility with version >= 3.6
[alecghica]check if url is in portal before redirect #2
[erral]manage came_from
[mamico]1.0a2 (unreleased)do userinforequest if there is a client.userinfo_endpoint
[mamico]1.0a1 (unreleased)Initial release.
[mamico]