Should it be that the user I use should be in openmrs by default? For more context, I created a temp user in keycloak and am able to login in directly but unable to link
Simply copying what I share on slack, the OAuth 2 Login module in OpenMRS does create new users automatically if they successfully authenticate through the SSO provider. However, I have a few clarifying questions and points:
How did you create the users for the OpenMRS client?
The client secret you added to oauth2.properties isn’t used as a traditional secret—instead, it acts as a bearer token for some web requests to the client. This token does expire after a period.
If you’re using Docker, note that using localhost in your URLs won’t work as expected due to container networking.
I recommend checking how this is implemented in the OpenMRS HIS setup and building on that. You should be able to adapt it to your specific needs—you may need docker compose for this (particularly looking at the keycloak service with the accompanying keycloak configs, and if you are able to build the OpenMRS HIS distro, you will find the reference oauth2.properties somewhere around this path target/distro/configs/openmrs/properties/oauth2.properties).
@jonathan it is also likely that there is another module providing conflicting Authentication schemes, such as is the case with the current Ref App Distro that contains an Authentication module.
Thanks @ruhanga, the issue was caused by the Authentication module, which was conflicting and redirecting to the default authentication method instead of using the OAuth2 protocol.
Not sure this has had traction so far, but it would be nice to provide a centralisdd auth registry in the core, more like spring’s AuthenticationManagerBuilder but with openmrs-specific hooks for priority ordering, conflict detection, and fallback mechanisms.
@thembo42 it makes sense to consider harvesting the feature into OpenMRS core once the approach has proven effective. A reasonable path might be to first update the OAuth2 Login module to use the proposed library/API. If that integration works well, it can later be brought into the core platform.
IMO, it’s still important to keep OpenMRS core as lightweight and generic as possible, enabling further feature extensions to be added/built through its modular architecture—which remains one of its key strengths, especially if not everyone uses the features.
Well, with 3.0 upgrades like TRUNK-6327, it fits naturally. Though termed as an “authorization plugin,” Spring Security’s broader framework (beyond just ACLs for authz) could provide a plumbing layer with support for multi-scheme delegation without conflicts, allowing runtime registration unlike overrides.
But yes, I really agree with the phased low-risk approach/validation.
So it would be potentially important to make a sub-task under TRUNK-6327 to provide evidence for-example, updates to oauth2login module, including success metrics on conflict resolution. This would help build the case for core harvesting while keeping things modular.
This is basically what the authentication module already provides. The issue is that the oauth2login module predates that module and so doesn’t take advantage of it’s more flexible authentication system.
By this it makes sense … I think the best approach would be to remove the Authentication module inorder to use the Oath2 module or disable it at startup
This works well new users are created automatically in OpenMRS at first login, and their basic details sync correctly.
However, I’m wondering
Is it possible to also create or map a Location for each user during OAuth2 login?
In other words, can the OAuth2 module handle location mapping, or would this require adding a custom listener or module to handle it after user creation?
This isn’t currently supported during the OAuth2 login process. That’s why users are prompted to select a location after logging in, since a user could potentially log in through any of the configured locations.
Adding custom listener logic to handle user-to-location mapping through a custom module could help but, why not use the Data Filter module for this instead?