Add hook to control account client access

Created on 2 May 2024, 7 months ago
Updated 19 June 2024, 6 months ago

Problem/Motivation

There is currently no possibility to add own access control to client like role access check or other custom strategies. See also: allow authentication per client per role Active

Steps to reproduce

Not needed

Proposed resolution

This needs a little bit more than the pre authorize hook:: #2051211: Add a hook_oauth2_server_pre_authorize()
The code needs to check a returning "deny"-Boolean and maybe an optional message to alter a default deny message to be rendered as json.

Remaining tasks

Add code.

User interface changes

No

API changes

No breaking change, just adding a new one.

Data model changes

No

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇩🇪Germany c-logemann Frankfurt/M, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @c-logemann
  • 🇩🇪Germany c-logemann Frankfurt/M, Germany

    According to hook_entity_access I think "hook_oauth2_server_authorize" would be a good name. I currently see only the need of $client and maybe the current user which is already loaded in Class OAuth2Controller. If somebody want to decide on server settings can this be done via loading serve from $client object.

    I will create a custom implementation before suggesting a change for the hook invocation.

  • 🇩🇪Germany c-logemann Frankfurt/M, Germany
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: php8.3_mysql8
    last update 7 months ago
    7 pass, 2 fail
  • Pipeline finished with Failed
    7 months ago
    Total: 237s
    #162906
  • 🇩🇪Germany c-logemann Frankfurt/M, Germany

    By starting with a proof of concept I figured out that it would be easy to get also control of "Automatic authorization".
    I wanted to keep I simple but also allow to react between modules so I started now with an "alter" Hook "hook_oauth2_server_authorize_alter" where &$authorization can be modified based on $client and $current_user. Next I just added a simple "AccessDeniedHttpException();" because I think if someone wants a more sophisticated reaction on a "deny" situation this can also be manged in the hook implementation like error messages and/or redirect etc.

  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • 🇩🇪Germany c-logemann Frankfurt/M, Germany
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 6 months ago
    22 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: php8.3_mysql8
    last update 6 months ago
    22 pass
  • Pipeline finished with Success
    6 months ago
    Total: 192s
    #197945
  • Status changed to Needs work 6 months ago
  • 🇦🇺Australia cafuego

    Okay, I think I know where you're coming from.

    I had a look at the PR and I *think* it's probably nicer to not throw an access denied exception but instead return a new 403 response:

    return new BridgeResponse([], 403);

    If you're going to add a new alter hook, you're going to have to add documentation for it in oauth2_server.api.php ;-)

  • Assigned to c-logemann
  • 🇩🇪Germany c-logemann Frankfurt/M, Germany

    Adding something to "oauth2_server.api.php" and a test was already planned. And I will think about the response situation.

Production build 0.71.5 2024