Skip to content

Refactor OAuth2Controller to actions. - #5605

Open
EreMaijala wants to merge 2 commits into
vufind-org:devfrom
EreMaijala:dev-refactor-oauth2controller
Open

Refactor OAuth2Controller to actions.#5605
EreMaijala wants to merge 2 commits into
vufind-org:devfrom
EreMaijala:dev-refactor-oauth2controller

Conversation

@EreMaijala

Copy link
Copy Markdown
Contributor

Moves a significant part of the logic to a new OAuth2ServerService.

*
* @return ResponseInterface
*/
public function action(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to move more of the logic in this method to OAuth2ServerService, but it's not easy because it's a multi-step operation with different outcomes depending e.g. on the user login status.

@demiankatz demiankatz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran tests on this locally and they all passed, but I've only just started looking at the code. See below for one small thing I noticed while waiting to get set up for the Summit. I'll provide a more thorough follow-up after the Summit is over -- just submitting this item now so it doesn't get lost/forgotten.

Comment thread module/VuFind/config/module.config.php Outdated
Moves a significant part of the logic to a new OAuth2ServerService.
@EreMaijala
EreMaijala force-pushed the dev-refactor-oauth2controller branch from f19d0f9 to d650826 Compare September 9, 2026 10:58
@demiankatz demiankatz added this to the 12.0 milestone Sep 9, 2026
@demiankatz demiankatz added the architecture pull requests that involve significant refactoring / architectural changes label Sep 9, 2026
@EreMaijala

EreMaijala commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Note: the functionality in the actions and OAuth2ServerService is almost completely covered by OAuth2Test Mink tests.

@demiankatz demiankatz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @EreMaijala. All tests are passing for me, but see below for some minor questions, suggestions and observations.

Comment on lines -131 to -138
if ($request->getMethod() == 'OPTIONS') {
// Disable session writes
$this->disableSessionWrites();
$response = $this->getResponse();
$response->setStatusCode(204);
$this->addCorsHeaders($response);
return $response;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately obvious to me where this logic ended up in the new version. Is this important, or am I just overlooking something?

protected function handleOAuth2Exception(
ResponseInterface $response,
string $function,
\Exception $e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertOAuthServerExceptionToResponse assumes that $e will have a generateHttpResponse method, which I assume is not part of the base exception class. Do we need a more specific type here, or some kind of type checking later?

Comment on lines +140 to +142
// Store OpenID nonce (or null if not present to clear any existing one)
// in the access token table so that it can be retrieved for token or
// user info action:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new line length, this looks a little unbalanced; might as well rewrap:

Suggested change
// Store OpenID nonce (or null if not present to clear any existing one)
// in the access token table so that it can be retrieved for token or
// user info action:
// Store OpenID nonce (or null if not present to clear any existing one) in the access
// token table so that it can be retrieved for token or user info action:

$response,
$this->oauth2Service->getUserInfo($request)
);
return $responseHelper->addCorsHeaders($response);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, the original version did not add CORS headers. Was that an oversight that is corrected here, or am I just missing something?


$responseHelper = $this->getHelper(ResponseHelper::class);
$response = $responseHelper->getJsonResponse($response, $this->oauth2Service->getJwks());
return $responseHelper->addCorsHeaders($response);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another where the original code does not seem to include CORS. Probably not a problem, just an observation.

Comment on lines +159 to +164
* @param string $allowedOrigin Allowed origin (see
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
* for details)
* @param bool $allowCredentials Whether credentials are allowed
* @param int $maxAge Maximum time in seconds the information
* from a preflight request can be cached

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested rewrap:

Suggested change
* @param string $allowedOrigin Allowed origin (see
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
* for details)
* @param bool $allowCredentials Whether credentials are allowed
* @param int $maxAge Maximum time in seconds the information
* from a preflight request can be cached
* @param string $allowedOrigin Allowed origin (see
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin for details)
* @param bool $allowCredentials Whether credentials are allowed
* @param int $maxAge Maximum time in seconds the information from a preflight request
* can be cached


$responseHelper = $this->getHelper(ResponseHelper::class);
$response = $responseHelper->getJsonResponse($response, $this->oauth2Service->getWellKnownConfiguration());
return $responseHelper->addCorsHeaders($response);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More added CORS.

{
$baseUrl = rtrim($this->baseUrl, '/');
$configuration = [
'issuer' => 'https://' . $_SERVER['HTTP_HOST'], // Same as OpenIDConnectServer\IdTokenResponse

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do this without using the $_SERVER superglobal? (I realize that the existing code already did this, but it seems like using an abstraction of the server variables would be more elegant).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

architecture pull requests that involve significant refactoring / architectural changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants