dokuwiki-plugin-oauth icon indicating copy to clipboard operation
dokuwiki-plugin-oauth copied to clipboard

Feature request: throw more checkable TokenResponseException in the request to the oauth provider

Open YoitoFes opened this issue 1 year ago • 0 comments

Feature Description

When an error occured during the request to the oauth provider, TokenResponseException is throwed.

https://github.com/cosmocode/dokuwiki-plugin-oauth/blob/e9e2f932fed3fcc2401ec8f2232a444b8a1bebde/HTTPClient.php#L26-L30

If an auth provider plugin is required to handle the exception, the field which the plugin can check the exception is only TokenResponseException->getMessage(). It would be great if the could throw a exception which we can check:

  • HTTP status code
  • HTTP error message

The background behind the request

YoitoFes/dokuwiki-plugin-oauthkeycloak/issues/7 requests the Keycloak service plugin to do the exception handling which is requred to check HTTP status code. Although it is achievable by parsing TokenResponseException's message (An error occured during the request to the oauth provider: ... [HTTP <status code>]), this approach is dependent on the hard-coded string in dokuwiki\plugin\oauth\HTTPClient, making the maintenance hard.

Potential solution

Define a new exception as follows.

class HttpResponseException extends TokenResponseException
{
    protected $httpStatusCode;
    protected $httpErrorMessage;

And HTTPClient throws the exception.

 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 
 if (!$ok || $http->status < 200 || $http->status > 299) { 
     $msg = "An error occured during the request to the oauth provider:\n"; 
     throw new HttpResponseException($msg . $http->error . ' [HTTP ' . $http->status . ']', $http->status, $http->error); 
 } 

Thank you.

YoitoFes avatar Jul 23 '24 16:07 YoitoFes