I have the need to add in an extra query parameter to the request to the authorization endpoint, specifically kc_idp_hint (https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.0...).

To do this I propose a new AuthorizeUrlOptionsAlterEvent.

I also want to add in the FormState parameter to authorize that is actually already being passed in from the LoginBlock form.

Code to come.

Comments

mikejw created an issue. See original summary.

mikejw’s picture

Status: Active » Needs review
StatusFileSize
new9.71 KB
sanduhrs’s picture

Status: Needs review » Needs work
mikejw’s picture

Status: Needs work » Needs review

In the context of a Plugin class I think best practice is to now use events - yeah? This is the equivalent of an alter hook. My impression is that hooks are generally on the way out (gone in Drupal 9+). If this was in the context of the openid_connect.module I would definitely be doing it via a hook alter.

mikejw’s picture

StatusFileSize
new5.22 KB

Updated to latest version of the module.

sharique’s picture

+1 for the RTBC,
Nice to have update to api.php file with example, a lot of people are new to event handler here.

mario steinitz’s picture

No offense, but introducing event handlers to the module for one hook while others don't support them? - I'd suggest sticking to the hooks for the current version of the module, and introducing events when the API gets an overhaul (e.g. to make the module Drupal 9 compliant).

Alter hooks are still a viable and often used method to allow for altering data in Drupal 8.

For your additional query parameter: For this use case, I suggest creating a custom client plugin for your IdP. Then you can implement the
OpenIDConnectClientInterface::authorize() method and add your custom query parameters to the authorization request. No need for an additional hook here. Or did I miss something?

sun’s picture

StatusFileSize
new5.32 KB
new694 bytes

The best we can do in D8 in terms of DX is to support both hooks and events (preferring events over hooks in terms of execution order).

I'd therefore recommend to go ahead with this patch, but add a regular alter hook, too. #BestOfBothWorlds #DX

Attached patch adds the regular alter hook to make both worlds happy.

We can amend the other hooks with events in a separate issue.

mario steinitz’s picture

@sun: Thanks for the revised patch. However, my concerns where more related to whether it makes much sense to introduce the event dispatcher for a single event only, whereas the module provides hooks only everywhere else.

That's why my idea is to provide this additional hook now, and then implement the event dispatcher as alternative for ALL existing hooks of the module. Targeted for the next beta version.

So modules extending openid_connect can choose between subscribing to events, or sticking to hooks until they will be deprecated for the entire module. This avoids a too messy API implementation, where modules may be required to use hooks and events.

mario steinitz’s picture

Created a general task to add event support for all hooks. TBD for the next beta release.

pingers’s picture

Re-roll against 8.x-1.x...

mario steinitz’s picture

Status: Needs review » Needs work

An update to the general purpose of this issue:

As a (new) co-maintainer of the module, I vote against adding an event/hook trigger within the plugin and will discuss this matter with sanduhrs before we make a final decision.

My reasoning:

The pluggable implementation of the OpenID Connect module allows for adding support for other IdPs than the ones that are shipped with the module. Instead of using hooks or events, third-party modules can and should provide their own plugins to support additional IdPs or implement special needs as different URL query parameters. This can easily done by overriding the authorize method of the base client.

We can't influence, how these plugins are written. We can only provide generic methods and helpers from within our module's service classes that reasonably support the general flow of OpenID Connect authorization and user property mapping. These generic methods allow for alterations by using our hooks and potentially soon events.

Adding a hook/event dispatch within the plugin means, that all custom plugins have to trigger these hooks/events, so that other modules can rely on them. Unfortunately, triggering the hook/event within such third-party plugin may be overseen, forgotten, or intentionally left out. Which in turn means, that to ensuring the event/hook is fired, we'd have to make all plugins depend in a private method of the base plugin class that would be responsible for dispatching this event. Or we would open up a potential source of hard-to-track errors where a hook/event provided/documented by our module will never be fired.

Both are scenarios, I'd pretty much like to avoid and suggest creating an own plugin for special use-cases instead.

Given the above, I'll set this certain issue back to "Needs work" till we find a better solution. It's also very likely that it will be closed as "Won't fix" in the near future.

mario steinitz’s picture

@mikejw: For your additional FormState parameter, please create a separate issue, if you still require it.

This would change the signature of the plugin authorize methods, and therefore is a breaking change to all current plugin implementations. We should decide in a dedicated issue of whether and when it will be done.

To support our and the community's decision, please add enough information, of why this change would be to the benefit of other users of the module (e.g. describe your use case to let us evaluate of whether it is a common issue that can be addressed). You may also try out the issue summary template for your next issue reported.

pingers’s picture

Another re-roll, keeping up with 8.x-1.x. Sorry for the noise.

pingers’s picture

Not sure why these patches are needing constant re-rolls :(

eiriksm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 KB

I arrived here since I did not want to override the entire method just to change the URL options in my custom plugin.

I would suggest adding a protected helper function in the base class which we can override. This would make it possible to override a "core" one as well, just by adding a custom plugin that extends it, and overrides this method. Much cleaner.

Patch attached.

jcnventura’s picture

Status: Needs review » Reviewed & tested by the community

I think that @eiriksm's approach here is indeed the best. If you need to alter the URL options, the plugins should be able to override that.

Since the patch in #16 is only refactoring existing code, I'm setting it to RTBC.

  • eiriksm authored e1c59c8 on 8.x-1.x
    Issue #2875537 by pingers, mikejw, sun, eiriksm, jcnventura: Add in an...
jcnventura’s picture

Title: Add in an event for altering the url_options in authorize method » Enable plugins to override the url_options in authorize method
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.