TsgcWebSocketClient | Client Authentication

TsgcWebSocket client supports 4 types of Authentications:

 

 

Authorization Basic

Is a simple authorization method where user and password are encoded and passes as an HTTP Header. Just set User and Password and enable only Basic Authorization type to use this method.


oClient := TsgcWebSocketClient.Create(nil);
oClient.Authorization.Enabled := true;
oClient.Authorization.Basic.Enabled := true;
oClient.Authorization.User := 'your user';
oClient.Authorization.Password := 'your password';
oClient.Authorization.Token.Enabled := false;
oClient.Authorization.URL.Enabled := false;
oClient.Authorization.Session.Enabled := false;
oClient.Active := True;

 

Authorization Token

Allows to get Authorization using JWT, requires you obtain a Token using any external tool (example: using an HTTP connection, OAuth2...).

If you Attach an OAuth2 component, you can obtain this token automatically. Read more about OAuth2.

Basically you must set your AuthToken and enable Token Authentication.


oClient := TsgcWebSocketClient.Create(nil);
oClient.Authorization.Enabled := true;
oClient.Authorization.Token.Enabled := true;
oClient.Authorization.Token.AuthToken := 'your token';
oClient.Authorization.Basic.Enabled := false;
oClient.Authorization.URL.Enabled := false;
oClient.Authorization.Session.Enabled := false;
oClient.Active := True;

 

Authorization Session

First client connects to server using an HTTP connection requesting a new Session, if successful, server returns a SessionId and client sends this SessionId in GET HTTP Header of WebSockets HandShake.

Requires to set UserName and Password and set Session Authentication to True.


oClient := TsgcWebSocketClient.Create(nil);
oClient.Authorization.Enabled := true;
oClient.Authorization.Session.Enabled := true;
oClient.Authorization.User := 'your user';
oClient.Authorization.Password := 'your password';
oClient.Authorization.Basic.Enabled := false;
oClient.Authorization.URL.Enabled := false;
oClient.Authorization.Token.Enabled := false;
oClient.Active := True;

 

Authorization URL

This Authentication method, just passes username and password in GET HTTP Header of WebSockets HandShake.

 


oClient := TsgcWebSocketClient.Create(nil);
oClient.Authorization.Enabled := true;
oClient.Authorization.URL.Enabled := true;
oClient.Authorization.User := 'your user';
oClient.Authorization.Password := 'your password';
oClient.Authorization.Basic.Enabled := false;
oClient.Authorization.Session.Enabled := false;
oClient.Authorization.Token.Enabled := false;
oClient.Active := True;