TsgcHTTP2Client | Client Authentication

HTTP/2 client supports 2 authentication types: Basic Authentication and OAuth2 Authentication.

 

Use OnHTTP2Authorization event to handle both types of authentication.

 

Basic 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";
  }
}

Bearer Token

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";
  }
}

Bearer value from Third-party

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 >"

 

OAuth2

Read the following article if you want to use our OAuth2 component with HTTP/2 client.