Use the debug log output
I recommend turning on debug logging in your Magnolia development project for more information.
Either use your Log4j configuration and add
<Logger name="org.pac4j" level="DEBUG"/>
<Logger name="com.nimbusds" level="DEBUG"/>
<Logger name="info.magnolia.sso" level="DEBUG"/>
or you can also utilize the Log Tools app.
Do not set up debug logging for security related data in production environments. You should disable it immediately after use if you are forced to enable it.
Check your IAM solution logs
You may find the solution to your problem by checking the logging capabilities of your IAM service if the error message you are receiving on the client side is incorrect or does not exist. Occasionally, it’s necessary to enable logging (like in Magnolia) to get the full picture. Checking the logs can be helpful if you are getting error messages that are unclear or wrong.
For example: Keycloak events
Examine token payloads
Once you have detailed output for Magnolia SSO, you will be able to pinpoint the problem with a failed setup. For example, you could search for status=200 or for profile: and examine the data to see if and how group information was added to the user’s token after authentication.
Token response: status=200, content=
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJGX1BRWXVqbEh3VEE0TjBndXRsLU1lREJXWHU4a3F1dkVnQmV2Qkx1YkgwIn0.eyJleHAiOjE2NjAzMDUzOTUsImlhdCI6MTY2MDMwNTA5NSwiYXV0aF90aW1lIjoxNjYwMzA1MDk1LCJqdGkiOiIwMjc0NmE2Yi02MmRmLTRkNmEtODY2MS05ZDg2ZDllMDM5ZDAiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgxODAvcmVhbG1zL21nbmwiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiYzM3YzFjNWMtZDIwMS00ZTA0LWFjMTgtNWQ1ODQxYjU5NTU2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibWFnbm9saWFBdXRob3IiLCJzZXNzaW9uX3N0YXRlIjoiMWE0OTJiMWQtNWEyMS00NjM1LTllYjgtYzI2NjZhYTZkNmJlIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsic3VwZXJ1c2VycyIsIm9m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RlIjoiMWE0OTJiMWQtNWEyMS00NjM1LTllYjgtYzI2NjZhYTZkNmJlIiwiYXRfaGFzaCI6InRZODRwTGx0RDF3RUE4ak9jQVByaHciLCJzaWQiOiIxYTQ5MmIxZC01YTIxLTQ2MzUtOWViOC1jMjY2NmFhNmQ2YmUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6IlN1cGluZG8gU3VwZXJ1c2VyIiwicGVuaXMiOlsic3VwZXJ1c2VycyIsIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iLCJkZWZhdWx0LXJvbGVzLW1nbmwiXSwicHJlZmVycmVkX3VzZXJuYW1lIjoic3VwZXJ1c2VyIiwiZ2l2ZW5fbmFtZSI6IlN1cGluZG8iLCJmYW1pbHlfbmFtZSI6IlN1cGVydXNlciIsImVtYWlsIjoic3VwZXJ1c2VyQGxvY2FsaG9zdCJ9.XWE4Bjndf6QmhKhVd35-pPC6VLb8wr-bbiv9SCf8Fpm7pw-N_5dEvp_n3ekX0BZk4Avq-sjUhoNMbv2LQyvQxLE8BHePAtQ7cc7YLQ3afQtKVqIxdWEMaIvScgkvp7swwq6GICxFrB1ayzHVFz4RGTD3Un72RzDf7HrdnVYcdl8LDH4GxiwpelQI3-mrpwHPaLfkAUJGe9uMVr9yxYYvYxVRgmKQ_qry6tsRQGq5p7RSMsie7kmO6lJhw38qPTbj7G68OpF4DsRQSMNNv96WK7_eirkNEndTEa2zTNLnoXMUkNyfAfkraDjGDHErrB5QrsRLvU7HjhRSjZeWOlmFnQ",
"not-before-policy":0,
"session_state":"1a492b1d-5a21-4635-9eb8-c2666aa6d6be",
"scope":"openid email profile"}
Use a tool like JWT.IO to look at OpenID Connect JWT token data (in the example above, the value for “id_token”)
Field mappings in config.yaml
After successful authentication, a temporary user is created in memory. The login will fail with a null pointer exception if the user object doesn’t have a username. The issue may be attributed to the userFieldMappings settings in your configuration.
userFieldMappings:
name: preferred_username
# ...
The example above doesn’t work with the default Okta setup because the OIDC token payload doesn’t have the preferred_username attribute. As a result, Magnolia SSO cannot assign a username and login to Magnolia fails, even after successfully authenticating to the IdP.
The actual content of token data that has been sent to your application can be seen by enabling debug logging in Magnolia.
A version that works for Okta:
userFieldMappings:
name: name
# ...
From a login point of view, the username is the most important thing to assign. Others may also be essential for the logic of your application, so if you struggle to receive correct values, please inspect the logs or adjust the configuration on the IDP or Magnolia side.
Issues with the SCOPE parameter
The scope parameter defines the kind of data that the IAM service will deliver after authentication. Typically, the scope is set to include openid, profile, and email. However, in certain circumstances, it may be necessary to modify or add values to the scope.
Besides the standards mentioned above, you are free to mess with scope settings on the backend of your security infrastructure. However, some services may require different scope values to achieve the same result.
For instance, if you want to check which groups users belong to, you need to add the groups value to your settings.
This scope setting might be worth considering:
oidc.scope: openid profile email
In Okta, the OIDC token payload does not contain the group’s data, despite having configured your application to receive such information.
The token data ends with the attribute at_hash:
"at_hash": "EJNUYPXZfpGNiM8maVimqQ"
If groups are configured and the scope contains groups, group information will be provided:
"at_hash": "2Ednv-6g0NPAmhUU3sy52g",
"groups": [
"Everyone",
"magnolia-superusers",
"travel-demo-editors",
"magnolia-users",
]
}
If nothing appears to be wrong
Test with local users
If everything looks good, user authentication works, also redirection to the Magnolia instance without an error message coming from the IDP, then the problem might be permissions on the Magnolia instance. The user might have been authenticated, but does not have any roles assigned, which means they do not have sufficient permissions.
To resolve this issue, create a local Magnolia user, assign the same groups/roles as the SSO user, and try to log in without SSO. If it is not working, the permissions are incorrect. You should consider that when using Magnolia SSO (at the time of writing), local logins are not possible, so you have to replicate the setup on a different instance.
Check your site configuration
Problems can also arise when there are issues with the site configuration. If all the OIDC settings and users appear to be correct and still, the login does not happen (watch for endless redirects), it could be a concern with the site. Keep an eye on this when certain stages work and others don’t.