YoitoFes / dokuwiki-plugin-oauthkeycloak

4 stars 6 forks source link

Nicer message for Error 400 after inactivity #7

Open fjf2002 opened 1 year ago

fjf2002 commented 1 year ago

In loose conjunction with #5,

when users click around in a 15 mins old dokuwiki webpage, they get a

OAuth: An error occured during the request to the oauth provider: [HTTP 400]

in their face. It simply should read, "You have been logged out. Please re-login."

Inside Keycloak.php, you could override the method refreshAccessToken with:

public function refreshAccessToken(TokenInterface $token) {
    try {
        return parent::refreshAccessToken($token);
    } catch (TokenResponseException $exc) {
        if ($exc->getMessage() === "An error occured during the request to the oauth provider:\n [HTTP 400]") {
            throw new TokenResponseException(
                'You have been logged out. Please re-login.',
                $exc->getCode(),
                $exc
        );
        } else {
            throw $exc;
        }
    }
}
YoitoFes commented 1 year ago

Thank you for the awesome suggestion. I will try it.

fjf2002 commented 1 year ago

I forgot to mention the use statements needed:

use OAuth\Common\Http\Exception\TokenResponseException;
use OAuth\Common\Token\TokenInterface;
fjf2002 commented 4 months ago

Hello @YoitoFes, any advancements on this topic? Thank You.

ZID-TU-Graz-Collab commented 1 month ago

We are also affected. Any news here @YoitoFes ? Thank you

YoitoFes commented 1 month ago

IMO, the suggested approach is dependent on the hard-coded string in dokuwiki\plugin\oauth\HTTPClient, making the maintenance hard.

Since I want to check the field/method which indicates HTTP status code directly, made the feature request (cosmocode/dokuwiki-plugin-oauth/issues/149).