HTTP/2 client supports 2 authentication types: Basic Authentication and OAuth2 Authentication.
Use OnHTTP2Authorization event to handle both types of authentication.
If server returns a header requesting Basic Authentication, set OnHTTP2Auithorization the username and password.
oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2Authorization := OnHTTP2AuthorizationEvent;
...
procedure OnHTTP2AuthorizationEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; const AuthType, AuthData: string; var UserName, Password, aToken: string; var Handled: Boolean);
begin
if AuthType = 'Basic' then
begin
UserName := 'user';
Password := 'secret';
end;
end;
If server returns a header requesting Bearer Token Authentication, set OnHTTP2Authorization the token.
oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2Authorization := OnHTTP2AuthorizationEvent;
...
procedure OnHTTP2AuthorizationEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; const AuthType, AuthData: string; var UserName, Password, aToken: string; var Handled: Boolean);
begin
if AuthType = 'Bearer' then
begin
aToken := 'bearer token';
end;
end;
If you already know the Bearer Value, because you have obtained using another method, you can pass the Bearer value as an HTTP header using the following properties of the request, just set before calling any HTTP Request method:
TsgcHTTP2Client.Request.BearerAuthentication = true
TsgcHTTP2Client.Request.BearerToken = "< value of the token >"
Read the following article if you want to use our OAuth2 component with HTTP/2 client.