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.
TsgcHTTP2Client oClient = new TsgcHTTP2Client()
oClient->OnHTTP2Authorization = OnHTTP2AuthorizationEvent;
...
void OnHTTP2AuthorizationEvent(TObject: *Sender; const TsgcHTTP2ConnectionClient *Connection; const string AuthType; const string AuthData; ref string UserName; ref string Password; ref string aToken; ref Boolean Handled)
{
if (AuthType == "Basic")
{
UserName = "user";
Password = "secret";
}
}
If server returns a header requesting Bearer Token Authentication, set OnHTTP2Authorization the token.
TsgcHTTP2Client oClient = new TsgcHTTP2Client()
oClient->OnHTTP2Authorization = OnHTTP2AuthorizationEvent;
...
void OnHTTP2AuthorizationEvent(TObject: *Sender; const TsgcHTTP2ConnectionClient *Connection; const string AuthType; const string AuthData; ref string UserName; ref string Password; ref string aToken; ref Boolean Handled)
{
if (AuthType == "Bearer")
{
aToken = "bearer token";
}
}
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 = trueTsgcHTTP2Client.Request.BearerToken = "< value of the token >"
Read the following article if you want to use our OAuth2 component with HTTP/2 client.