TsgcHTTP2Client › Events › OnHTTP2Authorization
Fires when the server requires authentication so the application can supply credentials or a bearer token.
property OnHTTP2Authorization: TsgcHTTP2ClientAuthorizationEvent;
// TsgcHTTP2ClientAuthorizationEvent = procedure(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; const AuthType, AuthData: String; var UserName, Password, Token: String; var Handled: Boolean) of object
—
OnHTTP2Authorization is raised when the server returns an authentication challenge (typically a 401 response) so the application can provide the credentials that should be used to retry the request. AuthType reports the scheme requested by the server (for example Basic or Bearer) and AuthData carries the extra challenge data sent back with it. Set UserName and Password for Basic authentication, or Token for Bearer / OAuth2 flows, and set Handled to True so the client resends the request with the supplied credentials. If Handled is left False the challenge is propagated to the caller as a normal response.
procedure OnHTTP2AuthorizationEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient;
const AuthType, AuthData: String; var UserName, Password, Token: String; var Handled: Boolean);
begin
if SameText(AuthType, 'Basic') then
begin
UserName := 'user';
Password := 'secret';
Handled := True;
end
else if SameText(AuthType, 'Bearer') then
begin
Token := 'eyJhbGciOi...';
Handled := True;
end;
end;