#1 2024-07-15 10:39:16

rdevine
Member
Registered: 2014-02-20
Posts: 52

Custom Authentication Class

I created a custom authentication class based on TRestServerAuthenticationDefault (to avoid re-implementing CheckPassword). My Auth() override is similar to the TRestServerAuthenticationDefault version but different enough that I can't use OnAuthenticationUserRetrieve. To get access to fSessionOS and AuthenticationFailed, which are both protected, I use the following hack:

TXAUriContext = class(TRestServerUriContext);

I then just cast CTxt to get to the protected members. This works fine on Windows but gives me a 216 runtime error on Linux/FPC (Invalid Typecast).

I'm no FPC expert so am not sure if there's a workaround, but would it be possible to have a setter for SessionOS and have AuthenticationFailed made public?

Thanks, Bob

Offline

#2 2024-07-15 16:57:30

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: Custom Authentication Class

Fixed on FPC by using the "as" cast rather than a hard one, i.e. this:

(Ctxt as TXAUriContext).fSessionOS := os;

Rather than this:

TXAUriContext(Ctxt).fSessionOS := os;

It would still be useful to have SessionOS and AuthenticationFailed accessible from other units though.

Cheers, Bob

Offline

#3 2024-07-16 06:28:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Custom Authentication Class

Offline

Board footer

Powered by FluxBB